点击button事件和拖动button事件冲突

来源:互联网 发布:淘宝上下架时间的技巧 编辑:程序博客网 时间:2024/04/30 18:01
之前写了button,悬浮在界面上,点击弹出新的界面,拖动可以移动到任何位置。但3DTouch出现之后,蛋疼的事情就发生了,你必须很轻很轻的去点击,button才能响应

UIControlEventTouchUpInside事件,否则就响应touchesMoved事件,很是蛋蛋疼。后来几经折腾,使用手势优化了下。

原来的UIControlEventTouchUpInside事件换成

UITapGestureRecognizer* tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapGesture)];

        [selfaddGestureRecognizer:tap];

 原来的- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event换成

        UIPanGestureRecognizer* pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(handelPan:)];

        [selfaddGestureRecognizer:pan];


移动的实现

-(void)handelPan:(UIPanGestureRecognizer*)gestureRecognizer{

   CGPoint curPoint = [gestureRecognizer locationInView:self.superview];

    [selfsetCenter:curPoint];

}


0 0