キーボードやその他の場所でのすべてのタッチを検出するだけで十分なようです。UIApplication
overrideにサブクラス化することでそれを行うことができますsendEvent:
。
UIApplicationDelegate
プロトコルを新しいメッセージ で拡張し、タッチ イベントを処理する前にapplication:willSendTouchEvent:
、UIApplication
サブクラスがデリゲートにメッセージを送信するようにします。
MyApplication.h
@interface MyApplication : UIApplication
@end
@protocol MyApplicationDelegate <UIApplicationDelegate>
- (void)application:(MyApplication *)application willSendTouchEvent:(UIEvent *)event;
@end
MyApplication.m
@implementation MyApplication
- (void)sendEvent:(UIEvent *)event {
if (event.type == UIEventTypeTouches) {
id<MyApplicationDelegate> delegate = (id<MyApplicationDelegate>)self.delegate;
[delegate application:self willSendTouchEvent:event];
}
[super sendEvent:event];
}
@end
MyApplicationDelegate
アプリのデリゲートをプロトコルに準拠させる必要があります。
AppDelegate.h
#import "MyApplication.h"
@interface AppDelegate : UIResponder <MyApplicationDelegate>
// ...
AppDelegate.m
@implementation AppDelegate
- (void)application:(MyApplication *)application willSendTouchEvent:(UIEvent *)event {
NSLog(@"touch event: %@", event);
// Reset your idle timer here.
}
MyApplication
最後に、アプリで新しいクラスを使用する必要があります。
main.m
#import "AppDelegate.h"
#import "MyApplication.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv,
NSStringFromClass([MyApplication class]),
NSStringFromClass([AppDelegate class]));
}
}