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

之前写了button,悬浮在界面上,点击弹出新的界面,拖动可以移动到任何位置。但3DTouch出现之后,蛋疼的事情就发生了,你必须很轻很轻的去点击,button才能响应

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

原来的UIControlEventTouchUpInside事件换成

UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGesture)];

        [self addGestureRecognizer:tap];

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

        UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handelPan:)];

        [self addGestureRecognizer:pan];


移动的实现

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

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

    [self setCenter:curPoint];

}


你可能感兴趣的:(IOS)