gpt4 book ai didi

iphone - UIAlertView:单击警报框外部时关闭 UIAlertView

转载 作者:行者123 更新时间:2023-12-03 21:02:13 27 4
gpt4 key购买 nike

嗨,我是 Xcode 新手,objective-C 需要这方面的帮助。我有一个没有按钮的 UIAlertView,它在单击自身时会被关闭。但我只想在单击警报框外部而不是内部时关闭它。谢谢

 //generating the alertview with no button

+(void) showAlertNoButtons:(NSString*)title text:(NSString*)text{

UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:title message:text
delegate:self cancelButtonTitle:nil
otherButtonTitles:nil];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissAlert:)];

alertView.delegate=self;
[alertView addGestureRecognizer:singleTap];
[alertView setMultipleTouchEnabled:YES];
[alertView setUserInteractionEnabled:YES];

[alertView show];
}
//
+(void)dismissAlert:(UITapGestureRecognizer *)gesture
{
UIAlertView* alertView =(UIAlertView *)gesture.view;
[alertView dismissWithClickedButtonIndex:0 animated:YES];

}

最佳答案

您需要调用- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndexAnimated:(BOOL)animated

当您点击其他任何地方时

这段代码将处理您的点击

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
[self dismissWithClickedButtonIndex:index animated:YES];
}

关于iphone - UIAlertView:单击警报框外部时关闭 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15540458/

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