Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS操作-如何从UIAction获取标准UIButton的事件数据?_Ios_Uibutton_Uievent - Fatal编程技术网

iOS操作-如何从UIAction获取标准UIButton的事件数据?

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

对于UIButton,touchDragInside上是否有一种方法可以告诉用户手势的方向?(上、下、左、右)


谢谢

您应该将按钮子类化,并覆盖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方法