我正在尝试使用 UIControlEventTouchDragEnter 设置一个按钮作为触发按钮方法的方式。具体来说,我有一个按钮,我希望当用户在按钮外按下手指并将手指拖入按钮边界时触发按钮的方法。
根据 apple ,此事件 UIControlEventTouchDragEnter 是:手指被拖入控件边界的事件。
但是,我无法让按钮触发。这是我的代码:
- (IBAction)touchDragEnter:(UIButton *)sender {
_samlpe.image = [UIImage imageNamed:@"alternate_pic.png"];
}
因此,当触发此按钮的 touchInto 时,该方法会将 _sample 的当前图像更改为此替代图像。如果我只使用 touchUpInside,单击按钮时图像确实会更改为备用图像。
有谁知道为什么这不起作用,或者有解决方法?谢谢!
最佳答案
touchDragEnter
仅在您最初点击按钮、将手指拖到按钮边界外,然后再次拖入按钮边界时触发。
您可能想在 View Controller 类中使用 touchesMoved
方法并根据触摸的位置检测输入的按钮:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:touch.view];
NSLog(@"%f - %f", touchLocation.x, touchLocation.y);
}
关于ios - 使用 UIControlEventTouchDragEnter 触发按钮的方法......但不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16661496/