9.5 触摸和手势:事件的传递的机制--演示代码
来源:互联网 发布:python读音 编辑:程序博客网 时间:2024/06/06 07:39
AppDelegate-----将UIWindow替换为TouchWindow
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[TouchWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; MainViewController *mainCtrl = [[MainViewController alloc] init]; self.window.rootViewController = mainCtrl; return YES;}
@interface TouchWindow :UIWindow
#import "TouchWindow.h"@implementation TouchWindow- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;}// 分发事件- (void)sendEvent:(UIEvent *)event{ [super sendEvent:event]; }// 响应者链传递- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"TouchWindow ---touchesBegan");}
@interface TouchView :UIView
#import "TouchView.h"@implementation TouchView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;}//事件的响应- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"TouchView---touchesBegan"); // 将事件传递给下一个响应者; [self.nextResponder touchesBegan:touches withEvent:event];}@end
#import "MainViewController.h"#import "TouchView.h"@interface MainViewController ()@end@implementation MainViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; TouchView *touchView = [[TouchView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)]; [touchView setBackgroundColor:[UIColor grayColor]]; [self.view addSubview:touchView]; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}// 测试响应者链传递- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"MainViewController-----touchesBegan"); // 将事件传递给下一个响应者; [self.nextResponder touchesBegan:touches withEvent:event];}@end
0 0
- 9.5 触摸和手势:事件的传递的机制--演示代码
- 9.4 触摸和手势:事件的传递的机制
- 触摸事件的传递机制
- 触摸事件的传递机制
- UI触摸手势,事件的分发传递
- 手势与触摸的事件分发机制
- 手势与触摸的事件分发机制
- IOS的触摸事件和手势处理
- (六十)触摸事件的传递和响应者链条、手势处理
- 触摸事件的传递
- ScrollView的上下联动事件 触摸事件传递机制
- 五、触摸事件的吞噬和传递
- 触摸事件的机制
- 解决 cell的点击事件和触摸手势的冲突
- 触摸事件和手势
- 手势和触摸事件
- 手势和触摸事件
- 触摸事件的传递机制和与Touch相结合的实践学习
- poj 3080 字符串
- Bluetooth in Android 4.2 and 4.3(一):综述
- 重要的手机短信丢失该怎么恢复
- 顺时针方向打印矩阵
- hao博文地址
- 9.5 触摸和手势:事件的传递的机制--演示代码
- UVA10250 The Other Two Trees
- uva 10250(数学)
- linux下文件打包和压缩
- [vim 小技巧] 在vim里保存只读文件
- dfs学习总结
- 链表(三)——链表删除冗余结点&插入结点到有序链表
- 堆和栈内存扩展方向问题
- hdu 2846 Repository