外部方法如何改变触发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/