在此文章中我们将实现iOS开发中常用到的一些手势触发功能,我们将控制器和view进行分离,在view中做事件绑定。
1.设置controller的rootView,在rootView的.m中实现触摸事件。
//实现触摸的相关方法
#pragma mark 触摸开始
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
self.backgroundColor = [UIColor colorWithRed:(arc4random()%256 / 255.0) green:(arc4random()%256 / 255.0) blue:(arc4random()%256 / 255.0) alpha:1];
}
#pragma mark 触摸移动当中
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}
#pragma mark 触摸结束
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%s",__func__);
}
#pragma mark 触摸被取消
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%s",__func__);
}