iOS手势操作
1:继承<UIGestureRecognizerDelegate> 委托
2:设置委托
UIPanGestureRecognizer *panRcognize=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
panRcognize.delegate=self;
[panRcognize setEnabled:YES];
[panRcognize delaysTouchesEnded];
[panRcognize cancelsTouchesInView];
[self.view addGestureRecognizer:panRcognize];
3:监控事件
#pragma UIGestureRecognizer Handles
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
//获取的是x y 的增量
NSLog(@"--移动的手势----- x:%f,y:%f",[recognizer translationInView:self.view].x,
[recognizer translationInView:self.view].y);
//获取的是x y 的位置
NSLog(@"--移动的手势-位置----- x:%f,y:%f",[recognizer locationInView:self.view].x,
[recognizer locationInView:self.view].y);
}
uiview手势移动
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//获取inner point
self.innerTouchPoint = [[touches anyObject]locationInView:self.leftView];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint point = [[touches anyObject]locationInView:(self.view)];
CGFloat y = point.y;
CGFloat x = point.x;
NSLog(@"--移动的手势-增量----- point:%f,%f",x,y);
self.leftView.frame = CGRectMake(x-self.innerTouchPoint.x, y-self.innerTouchPoint.y, 30, 400);
// NSLog(@"--移动的手势-位置----- x:%f,y:%f",[recognizer locationInView:self.view].x,
// [event locationInView:self.view].y);
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。