ios - 触及范围外

标签 ios touch

外部方法如何改变触发touch up的距离? UIButton 的 touch up outside 方法仅在 touch up 位置距离按钮约 100 像素时触发,因为我可以看到当从内部拖动到外部约 100 像素时按钮的突出显示发生了变化。 有没有办法缩短距离? 谢谢!

最佳答案

你能试试吗

- (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
    }
}

希望对您有所帮助,请给我反馈,这样我就知道发生了什么,然后我可以编辑我的代码来帮助您,祝您好运:)。

显着:事件将包含坐标

UPDATE://根据您在下方的评论 请尝试,在if条件下,您需要检查您的端点类型

假设你想缩短到距按钮 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
    }
}

希望对你有帮助:)

关于ios - 触及范围外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13319759/

相关文章:

ios - 嵌套核心数据获取

ios - 使用图像序列为开关设置动画

iphone - UIImageView & 显存

c# - 在 WP8.1 中拦截 ManipulationDelta 的问题

audio - 用于录制音频的插件

ios - 是否可以仅更新应用商店中的内部版本号?

ios - 如何使 UIScrollView 高度等于内容高度?

javascript - 使用 WinJs 构建的 Pivot 的滑动事件在 Windows Phone 上不起作用

android - 奇怪的行为 ScaleAnimation setFillAfter(true)/false

audio - sencha Touch中的音频