对于UIButton,touchDragInside是否有办法告诉手势的方向? (上,下,左,右)
- (IBAction)buttonTouchedUpInside:(UIButton *)sender forEvent:(UIEvent *)event {
}
谢谢!
答案 0 :(得分: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方法。