Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 替换UIWindow_Ios_Cordova_Touch_Uiwindow - Fatal编程技术网

Ios 替换UIWindow

Ios 替换UIWindow,ios,cordova,touch,uiwindow,Ios,Cordova,Touch,Uiwindow,我使用phonegap通过js开发web应用程序,但我需要某些只能在objective c中实现的功能。具体来说,我想在webview上注册触摸,以触发覆盖视图的自动关闭。通过谷歌搜索“detect touch”(检测触摸)可以找到一种解决方案,即人们应该将UIWindow子类化并覆盖sendEvent,以便检测所需的视图是否被触摸 这实际上非常有效,但我注意到phonegap已经在他们的代码中分配并设置了UIWindow的实例,因此我无法使用子类UIWindow。因此,我发现这个解决方案是可行

我使用phonegap通过js开发web应用程序,但我需要某些只能在objective c中实现的功能。具体来说,我想在webview上注册触摸,以触发覆盖视图的自动关闭。通过谷歌搜索“detect touch”(检测触摸)可以找到一种解决方案,即人们应该将
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
来破坏任何东西