简体   繁体   English

触及外界

[英]touch up outside range

How to change the distance for triggering touch up outside method? 如何改变触发外部方法的距离? UIButton's touch up outside method only fire when touch up location is about 100 pixels away from the button, as i can see the button's highlight changed when drag from inside about 100 pixels to outside. UIButton的修饰外部方法仅在触摸位置距离按钮大约100个像素时触发,因为我可以看到当从内部约100个像素向外拖动时按钮的高光变化。 Is there a way to shorten the distance? 有没有办法缩短距离? Thanks! 谢谢!

could you please try 你可以试试吗

- (IBAction)btnDragged:(id)button withEvent:(UIEvent*)event {
    UITouch *t = [[event touchesForView:yourButtonView] anyObject];
    CGPoint touchLocation = [t locationInView:self.view];
    //NSLog(@"%@", NSStringFromCGPoint(touchLocation));

    if (your condition, using CGPoint to check for shorten distance, compare your button location and touchLocation) {
      //fire some stuff
    }
}

hope it help, please give me a feedback, so I know what's going on, then I can edit my code to help you, Good luck :). 希望它有所帮助,请给我一个反馈,所以我知道发生了什么,然后我可以编辑我的代码来帮助你,祝你好运:)。

remarkable: event will contain the coordinates 非凡:事件将包含坐标

UPDATE:// according to your comment below please try, in if condition, you need to check that what kind of class of your end point 更新://根据您的评论,请尝试,如果有条件,您需要检查您的终点是什么类

Assume that you want to shorten to 50 pixels away from button, so the condition should be similar to this. 假设您希望缩短到距离按钮50像素,因此条件应与此类似。

if ( fabsf(yourButton.frame.x - touchLocation.x) <= 50 && fabsf(yourButton.frame.y - touchLocation.y) <= 50 ) {

    UIView *v = [self.view hitTest:touchLocation withEvent:nil];
    if ([v isKindOfClass:[UIButton class]]) //check that it is button B or not
    {
        //do your stuff
    }
}

hope it help :) 希望它有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM