1

对于 UIButton,touchDragInside 上有没有办法告诉手势的方向?(上下左右)

- (IBAction)buttonTouchedUpInside:(UIButton *)sender forEvent:(UIEvent *)event {
}

谢谢!

4

1 回答 1

1

您应该对按钮进行子类化并覆盖 beginTrackingWithTouch:withEvent:、continueTrackingWithTouch:withEvent: 和 endTrackingWithTouch:withEvent:。我在下面的代码中输入的日志应该可以帮助您开始您想做的事情。

 - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
   NSLog(@"%@",NSStringFromCGPoint([[event.allTouches anyObject] locationInView:self]));
    return YES;
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
    NSLog(@"%@",NSStringFromCGPoint([[event.allTouches anyObject] locationInView:self]));
    return YES;
}

-(void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
    NSLog(@"%@",NSStringFromCGPoint([[event.allTouches anyObject] locationInView:self]));
}

如果你只对整体方向感兴趣,你可以只看 beginTracking 数和 endTracking 数,而忽略 continueTracking 方法。

于 2013-04-19T03:20:51.433 回答