要趕上全球所有觸摸事件,我結束了繼承的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。 –