iOS操作-如何从UIAction获取标准UIButton的事件数据?
对于UIButton,touchDragInside上是否有一种方法可以告诉用户手势的方向?(上、下、左、右)iOS操作-如何从UIAction获取标准UIButton的事件数据?,ios,uibutton,uievent,Ios,Uibutton,Uievent,对于UIButton,touchDragInside上是否有一种方法可以告诉用户手势的方向?(上、下、左、右) 谢谢 您应该将按钮子类化,并覆盖beginTrackingWithTouch:withEvent:、continueTrackingWithTouch:withEvent:、endTrackingWithTouch:withEvent:。我在下面代码中输入的日志应该可以让您开始做您想做的事情 - (BOOL)beginTrackingWithTouch:(UITouch *)touc
谢谢 您应该将按钮子类化,并覆盖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方法。您应该将按钮子类化,并使用Touch:withEvent:、continueTrackingWithTouch:withEvent:、endTrackingWithTouch: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方法