9.5 触摸和手势:事件的传递的机制--演示代码
2014-07-19 16:35
381 查看
AppDelegate-----将UIWindow替换为TouchWindow
@interface TouchWindow :UIWindow
@interface TouchView :UIView
- (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
相关文章推荐
- 9.4 触摸和手势:事件的传递的机制
- 关于android触摸事件传递机制
- Android_触摸事件传递机制
- Android ViewGroup 触摸事件传递机制
- Android 触摸事件传递机制
- Android 触摸事件传递机制
- Android 触摸事件传递机制
- Android View触摸事件传递机制
- Android View触摸事件传递机制
- 触摸事件的传递机制和与Touch相结合的实践学习
- Android事件传递机制、手势检测
- Android ViewGroup 触摸事件传递机制
- (六十)触摸事件的传递和响应者链条、手势处理
- android中的Touch触摸事件传递机制
- Android 触摸事件传递机制
- android触摸事件传递机制以及onInterceptTouchEvent()和onTouchEvent()总结
- Android 触摸事件传递机制
- Android View 触摸事件传递机制
- 彻底掌握Android的Touch触摸事件传递机制
- UI触摸手势,事件的分发传递