iphone - 当用户点击 iPhone 中的上方 View 时隐藏 UIActionSheet

标签 iphone ios xcode uiactionsheet

我想在操作表上设置操作,这样当用户点击操作表上方时它会被取消。
我想这样做是因为我不想在操作表中添加取消按钮。用户可以通过点击休息区 View 来取消操作表,而不是取消按钮。
关于如何在 iPhone 中执行此操作的任何建议。
谢谢

最佳答案

// 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];
}

参见 here .

请注意,这已经发生在 iPad 上。

关于iphone - 当用户点击 iPhone 中的上方 View 时隐藏 UIActionSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8683752/

相关文章:

iphone - 使用其他应用程序打开 pdf

ios - 以编程方式将 View 对象定位在其最近邻居的下方

ios - 如何在所有 View 的顶部添加 UIView?

ios - UITableView 不显示在模拟器中

iOS 模拟器 : "Unable to simultaneously satisfy constraints" with empty app

ios - Swift 中来自 nib 的自定义 UITableViewCell

ios - HLSCatalog 苹果示例应用程序

iphone - long double 的格式说明符(我想截断小数点后的 0)

ios - 在应用程序运行时在 AppDelegate 中运行 didFinshLaunchingWithOptions?

ios - 如果通过电缆或网络从 xcode 安装,则为设备推送 token 注册不同的值