当你在外面点击它时,如何使用uiactionsheet消失?

Chr*_*ris 12 iphone objective-c uiactionsheet

如果你在外面点击它,如何让你的uiactionsheet消失?这适用于iPhone.显然,ipad默认这样做(我可能错了).

Chr*_*ris 15

好的,有一个解决方案 以下内容适用于UIActionSheet的子类

// For detecting taps outside of the alert view
-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:self];
    if (p.y < 0) { // They tapped outside
        [self dismissWithClickedButtonIndex:0 animated:YES];
    }
}

-(void) showFromTabBar:(UITabBar *)view {
    [super showFromTabBar:view];

    // Capture taps outside the bounds of this alert view
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)];
    tap.cancelsTouchesInView = NO; // So that legit taps on the table bubble up to the tableview
    [self.superview addGestureRecognizer:tap];
    [tap release];
}
Run Code Online (Sandbox Code Playgroud)

它的要点是在动作表的超视图中添加一个手势识别器,并测试所有水龙头以查看它们是否在操作表之上.

  • 我目前正在尝试这个解决方案,但是我发现UIAlertView会吸收所有事件,所以tapOut:方法永远不会被手势识别器调用.因此,该解决方案根本不起作用. (2认同)