嗨,我是 Xcode n 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];
}