iOS拦截控件事件,处理后继续执行原来的消息传递流程
来源:互联网 发布:linux 7 配置ip地址 编辑:程序博客网 时间:2024/04/29 23:36
#import <objc/objc.h>
#import <objc/runtime.h>
- (void)sendEventHooked:(UIEvent *)event {
//在这里做你想做的事情吧
NSLog(@"截获事件:%@", [eventdescription]);
//执行原来的消息传递流程
[selfperformSelector:@selector(sendEventOriginal:)withObject:event];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Method sendEvent =class_getInstanceMethod([UIWindowclass],@selector(sendEvent:));
Method sendEventMySelf =class_getInstanceMethod([selfclass],@selector(sendEventHooked:));
IMP sendEventImp =method_getImplementation(sendEvent);
class_addMethod([UIWindowclass],@selector(sendEventOriginal:), sendEventImp,method_getTypeEncoding(sendEvent));
IMP sendEventMySelfImp =method_getImplementation(sendEventMySelf);
class_replaceMethod([UIWindowclass],@selector(sendEvent:), sendEventMySelfImp,method_getTypeEncoding(sendEvent));
self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
// Override point for customization after application launch.
if ([[UIDevicecurrentDevice]userInterfaceIdiom] ==UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewControlleralloc]initWithNibName:@"ViewController_iPhone"bundle:nil]autorelease];
}else {
self.viewController = [[[ViewControlleralloc]initWithNibName:@"ViewController_iPad"bundle:nil]autorelease];
}
self.window.rootViewController =self.viewController;
[self.windowmakeKeyAndVisible];
return YES;
}
然后可以在其它地方创建按钮,就可以截获到按钮触摸事件!
- iOS拦截控件事件,处理后继续执行原来的消息传递流程
- 通过消息拦截达到在Delphi控件中屏蔽原有事件处理的一种方法
- iOS 事件传递流程
- iOS事件拦截处理
- iOS事件拦截处理
- iOS事件拦截处理
- iOS事件拦截处理
- Spring拦截器和异常处理的执行流程
- 如何处理被拦截的键盘消息事件
- iOS UIEvent 事件传递 流程
- iOS开发-Day28-UI自定义控件&消息传递&事件传递机制
- 【Android】事件传递:向下拦截,向上处理
- 【iOS开发-88】事件传递原理解释哪个控件处理事件以及响应者链条的介绍
- windows的开发流程--事件通知和消息处理
- APNS推送消息到达后的处理流程
- APNS推送消息到达后的处理流程
- 消息的处理流程
- Android 控件的触摸事件传递与处理
- 函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal)
- hdu4366
- 操作系统常见问题解答
- linux 与 unix区别
- Attribute在.NET编程中的应用(五)
- iOS拦截控件事件,处理后继续执行原来的消息传递流程
- Oracle操作
- 黑马程序员-------Java集合
- Uva-10054-The Necklace
- 客户端JavaScript
- POJ 计算几何入门题目推荐(转)
- signed和unsigned的比较
- 结构体对齐问题
- 研发周报:神奇!1KB JavaScript代码编写的3D蜜蜂