相关疑难解决方法(0)

将UIView或UIWindow置于状态栏上方

我的目标是在iPhone应用程序顶部的状态栏上方绘制一个隐形按钮(尺寸为320*20像素).

无论我尝试什么,都会出现问题:

  1. 例如,我尝试创建一个新视图.当我想将视图放在我的应用程序顶部时,它总是消失在状态栏后面而不是在它前面!

  2. 我在Stackoverflow上找到了另一个好主意: 将UIView添加到所有其他视图之上,包括StatusBar 即使不推荐第二个UIWindow,我也尝试实现它.它直到我注意到一个问题时才按照我想要的方式工作:键盘在需要时不再出现(例如在文本框中单击时)!

我怎么可能解决这个问题?或者有更好的解决方法吗?这是我创建第二个窗口的代码:

// Create window
statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
[statusWindow makeKeyAndVisible];

// Create statusBarButton
statusBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect buttonFrame2 = statusBarButton.frame;
buttonFrame2.size = CGSizeMake(320,20);
statusBarButton.frame = buttonFrame2;
[statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; 

// Place button into the new window
[statusWindow addSubview:statusBarButton];
Run Code Online (Sandbox Code Playgroud)

iphone keyboard statusbar uiview uiwindow

7
推荐指数
3
解决办法
2万
查看次数

标签 统计

iphone ×1

keyboard ×1

statusbar ×1

uiview ×1

uiwindow ×1