通过UIWindows单击 [英] Click through UIWindows
问题描述
在所有内容中,我一直都遵循以下示例来创建<在 statusBar
顶部的code> UIWindow 中。
I've been following this example in everything to create a UIWindow
on top of the statusBar
.
我的 UIWindow
显示在 statusBar
的顶部一切都很好,但应用程序的实际视图(带有按钮的视图)无法响应我的操作:
My UIWindow
gets displayed on top of the statusBar
and all is fine, but the actual view of the app (the one with the button) doesn't respond to my actions:
我正在使用Storyboards和iOS6。
这是创建 statusBar
叠加层的代码:
I'm using Storyboards and iOS6.
Here's my code for creating a statusBar
overlay:
- (void)viewDidAppear:(BOOL)animated {
UIWindow *overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
AppDelegate *app = [[UIApplication sharedApplication] delegate];
overlayWindow.rootViewController = app.window.rootViewController;
app.window = overlayWindow;
[overlayWindow makeKeyAndVisible];
}
statusBar
没有响应,我无法点击 UIButton
。是否可以通过某种方式使带有我应用程序界面的UIWindow忽略 ACStatusBarOverlayWindow
而接受触摸?怎么办呢?
The view under the statusBar
does not respond and I can't tap on the UIButton
. Is it possible to somehow make the UIWindow with the interface of my app accept the touches ignoring the ACStatusBarOverlayWindow
? How can that be done?
推荐答案
通常,如果按钮对触摸没有响应,那是因为按钮在边界之外它是父级的UIView。
Usually if a button does not respond to a touch it's because the button is outside of the bounds of it's parent's UIView.
您的代码似乎不是解决您要解决的问题的适当方法。如果您只需要窗口具有状态栏,或者只需要向当前视图添加按钮,那么您执行此操作的方式可能是错误的。
Your code does not seem to be the appropriate approach to the problem you're trying to solve. If you just need your window to have a status bar, or you just need to add a button to you current view, the way you're doing it is probably incorrect.
就我个人而言,我从来没有见过有人在viewDidAppear中实例化UIWindow,因为该应用程序带有它自己的UIWindow。您应该使用UIView并向其中添加覆盖。
Personally I've never seen anyone instantiate a UIWindow in a viewDidAppear, since the app comes with it's own UIWindow. You should be using a UIView and adding your overlay to it.
请注意,如果要以尝试的方式进行操作,则窗口将至少需要一个框架。因此initWithFrame:CGRectZero可能是initWithFrame:CGRectMake(0,0,320,480)或类似的东西。
As a side note if you were to do it the way you're attempting to, then your window would at least need a frame. So initWithFrame:CGRectZero would be initWithFrame:CGRectMake(0,0,320,480) or something along those lines.
解决此问题的更好方法是实例化UIViewController并将其设置作为您的rootViewController。或只需将按钮添加到当前viewController的视图中。
A better way to approach the problem is to instantiate a UIViewController and set it as your rootViewController. Or simply add your button to the current viewController's view.
- (void)viewDidLoad {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(myMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Tap Me" forState:UIControlStateNormal];
[button sizeToFit];
[self.view addSubview:button];
}
这篇关于通过UIWindows单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!