iOS手势操作

作者: 光明程辉 | 来源:发表于2016-10-31 00:11 被阅读64次

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{
    
}

相关文章

网友评论

    本文标题:iOS手势操作

    本文链接:https://www.haomeiwen.com/subject/lcguuttx.html