要赶上全球所有触摸事件,我结束了继承的UIWindow如下:
// CustomUIWindow.h
#import <UIKit/UIKit.h>
#define kTouchPhaseBeganCustomNotification @"TouchPhaseBeganCustomNotification"
@interface CustomUIWindow : UIWindow
@property (nonatomic, assign) BOOL enableTouchNotifications;
@end
// CustomUIWindow.m
#import "CustomUIWindow.h"
@implementation CustomUIWindow
@synthesize enableTouchNotifications = enableTouchNotifications_;
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event]; // Apple says you must always call this!
if (self.enableTouchNotification) {
[[NSNotificationCenter defaultCenter] postNotificationName:kTouchPhaseBeganCustomNotification object:event];
}
}@end
然后每当我需要开始听全触控全球我做以下:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stopThumbnailWobble:)
name:kTouchPhaseBeganCustomNotification
object:nil];
((CustomUIWindow *)self.window).enableTouchNotification = YES;
在stopThumbnailWobble我删除观察者和PROC通过UITouch事件来决定是否删除拇指:
- (void)stopThumbnailWobble:(NSNotification *)event
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kTouchPhaseBeganCustomNotification
object:nil];
((CustomUIWindow *)self.window).enableTouchNotification = NO;
UIEvent *touchEvent = event.object;
// process touchEvent and decide what to do
...
希望这有助于他人。
我的应用程序崩溃给出此错误消息:[UIWindow setEnableTouchNotifications:]:无法识别的选择器发送到实例 –
您是否继承了UIWindow? –
不,我把它解决了,因为我的问题被其他方式解决..谢谢反正..至少我了解了一种新的东西,UIWindow是这样subclassed。 –