gpt4 book ai didi

iphone - 当您点击外部(例如上方)时,如何使 uiactionsheet 关闭?

转载 作者:太空狗 更新时间:2023-10-30 03:21:36 27 4
gpt4 key购买 nike

当您点击外部(例如上方)时,如何关闭 uiactionsheet?这是针对 iPhone 的。显然 ipad 默认会这样做(我可能错了)。

最佳答案

好的,找到解决方案了。以下适用于 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];
}

它的要点是在操作表的父 View 中添加一个手势识别器,并测试所有的点击以查看它们是否在操作表之上。

关于iphone - 当您点击外部(例如上方)时,如何使 uiactionsheet 关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6172212/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com