我正在做与自定义警报相关的应用程序。当我单击警报 View 上的确定按钮时,用于显示具有透明背景的警报 View 的书面代码 - 警报消失。
当我触摸透明 View 时发生同样的事情我需要帮助我的代码也在下面 :
- (void)didCustomPopUpAlertLoad:(UIView *)parentView andtitle:(NSString *)strTitle {
[self setRootView:parentView];
self.lblAlertMessage.text = strTitle;
//Add alertview into transparent view to hide parent view interaction
UIView *transparentView = [[UIView alloc] initWithFrame:parentView.bounds];
[transparentView setBackgroundColor:[UIColor clearColor]];
[transparentView addSubview:self];
float x = (int)(transparentView.bounds.size.width - self.bounds.size.width)>>1;
float y = (int)(transparentView.bounds.size.height - self.bounds.size.height)>>2;
[self setFrame:CGRectMake(x, y+62, self.bounds.size.width, self.bounds.size.height)];
// [self setFrame:CGRectMake(x+10, y+62, self.bounds.size.width, self.bounds.size.height)];
[self.window addSubview:transparentView];
[self.window makeKeyAndVisible];
[[transparentView subviews]
makeObjectsPerformSelector:@selector(setUserInteractionEnabled:)
withObject:[NSNumber numberWithBool:FALSE]];
}
-(void)didCustomPopUpUnload{
[self.superview removeFromSuperview];
// Set up the fade-in animation
self.window = nil;
}
-(IBAction)didActionOkAlertPopUp:(id)sender{
[self didCustomPopUpUnload];
}
最佳答案
创建自定义透明 View 然后覆盖此方法
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
将您的警报 View 添加到此 View 中并将此 View 用作全屏 View 。
您可以使用 event
参数来计算以了解 alertview 内部或外部的用户触摸。
关于IOS:在后台单击时删除 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27718004/