Ios 替换UIWindow
我使用phonegap通过js开发web应用程序,但我需要某些只能在objective c中实现的功能。具体来说,我想在webview上注册触摸,以触发覆盖视图的自动关闭。通过谷歌搜索“detect touch”(检测触摸)可以找到一种解决方案,即人们应该将Ios 替换UIWindow,ios,cordova,touch,uiwindow,Ios,Cordova,Touch,Uiwindow,我使用phonegap通过js开发web应用程序,但我需要某些只能在objective c中实现的功能。具体来说,我想在webview上注册触摸,以触发覆盖视图的自动关闭。通过谷歌搜索“detect touch”(检测触摸)可以找到一种解决方案,即人们应该将UIWindow子类化并覆盖sendEvent,以便检测所需的视图是否被触摸 这实际上非常有效,但我注意到phonegap已经在他们的代码中分配并设置了UIWindow的实例,因此我无法使用子类UIWindow。因此,我发现这个解决方案是可行
UIWindow
子类化并覆盖sendEvent
,以便检测所需的视图是否被触摸
这实际上非常有效,但我注意到phonegap已经在他们的代码中分配并设置了UIWindow
的实例,因此我无法使用子类UIWindow
。因此,我发现这个解决方案是可行的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
bool res= [super application:application didFinishLaunchingWithOptions:launchOptions];
// ok, now this part is kind of ugly
// replace normal UIWindow with tap-detection enabled version
[self.viewController.view removeFromSuperview];
CGRect screenBounds = [ [ UIScreen mainScreen ] bounds ];
TapDetectWindow* tapWindow= [[[TapDetectWindow alloc] initWithFrame:screenBounds] autorelease];
tapWindow.tapDelegate= self.logic;
tapWindow.targetView= self.webView;
self.window = tapWindow;
self.window.autoresizesSubviews = YES;
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return res;
}
虽然这就像一个符咒(还没有任何副作用),但我想知道这是否是一个好方法,或者在设置并使其可见后,我是否打算通过替换UIWindow
来破坏任何东西