对于UIButton来说,在touchDragInside上有什么方法可以判断手势的方向吗?(上、下、左、右)
- (IBAction)buttonTouchedUpInside:(UIButton *)sender forEvent:(UIEvent *)event {
}谢谢!
发布于 2013-04-19 11:20:51
您应该对按钮进行子类化,并重写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方法。
https://stackoverflow.com/questions/16096256
复制相似问题