我有一个选项卡栏应用程序,在其中一个选项卡中我有一个 MKMapView。在此视图中,我的 viewDidLoad 正在初始化 UIButton 的长按手势识别器。当按下此按钮并帮助时,它会显示一个包含 5 个按钮 + 取消按钮的 UIActionSheet。每个按钮代表一个缩放级别:“世界”、“国家”、“州”、“城市”、“当前位置”。选择 UIActionSheet 中的按钮会将底层 MKMapView 缩放到该级别。
我遇到的问题是所有按钮(包括取消按钮)都需要双击才能关闭 UIActionSheet。这不是预期的行为——它应该像其他 UIActionSheet 一样在按下按钮一次后关闭。第一次按下后,我可以看到地图缩放到 UIActionSheet 后面的适当级别,因此我知道触摸正在正确的按钮上注册,但按钮在第一次按下时不会突出显示蓝色,并且 UIActionSheet 不会关闭。直到我第二次按下按钮,它才会突出显示蓝色,然后关闭。
如果我删除长按手势识别器并在“内部触摸”上显示 UIActionSheet,那么一切都会按预期进行。所以我知道这个手势在某种程度上造成了干扰,有什么修复或解决方法的想法吗?或者这是一个应该向 Apple 报告的错误吗?
- (void) viewDidLoad {
// intitialize longpress gesture
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(zoomOptions:)];
longPressRecognizer.minimumPressDuration = 0.5;
longPressRecognizer.numberOfTouchesRequired = 1;
[self.currentLocationButton addGestureRecognizer:longPressRecognizer];
}
- (IBAction) zoomOptions:(UIGestureRecognizer *)sender {
NSString *title = @"Zoom to:";
UIActionSheet *zoomOptionsSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"World", @"Country", @"State", @"City", @"Current Location", nil];
[zoomOptionsSheet showFromTabBar:appDelegate.tabbarController.tabBar];
}
安娜·卡列尼娜 https://stackoverflow.com/users/467105/anna-karenina是对的,并且link https://stackoverflow.com/questions/7688329/uilongpressgesturerecognizer-on-uitableviewcell-double-call/7688584#7688584提供帮助我弄清楚了。基本上,UILongPressGestureRecognizer
是一个经历各种状态变化的“连续手势”。我需要检查适当的状态,就我而言是UIGestureRecognizerStateBegan
因为我想要UIActionSheet
在按住按钮之后但在释放并停止手势之前呈现。我所要做的就是结束演示文稿UIActionSheet
在检查适当状态的 if 语句中。现在它按预期工作了。
- (IBAction) zoomOptions:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
NSString *title = @"Zoom to:";
UIActionSheet *zoomOptionsSheet = [[UIActionSheet alloc]
initWithTitle:title
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"World", @"Country",
@"State", @"City",
@"Current Location", nil];
[zoomOptionsSheet showFromTabBar:appDelegate.tabbarController.tabBar];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)