This question already has answers here:
iOS How to dismiss UIAlertView with one tap anywhere?
(2个答案)
7年前关闭。
嗨,我是Xcode n目标C的新手,需要帮助。
我有一个没有按钮的UIAlertView,单击它本身会被关闭。但是我只想单击警报框外部而不是内部而将其关闭。谢谢
(2个答案)
7年前关闭。
嗨,我是Xcode n目标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)buttonIndex animated:(BOOL)animated
当您点击其他任何地方
这段代码将处理您的点击
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self dismissWithClickedButtonIndex:index animated:YES];
}
关于iphone - UIAlertView:在警报框外侧单击时关闭UIAlertView ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15540458/
10-13 06:32