【发布时间】:2014-12-31 07:54:47
【问题描述】:
我正在做与自定义警报相关的应用程序。当我单击警报视图上的确定按钮时,用于显示具有透明背景的警报视图的书面代码 - 警报消失。
当我触摸透明视图时,同样的事情发生时我需要帮助,我的代码如下 :
- (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];
}
【问题讨论】:
-
在透明视图上添加点击手势。
-
如果您的透明视图的大小不等于窗口的大小,当您触摸透明视图之外的区域时,您将永远无法检测到触摸。如果无法全屏透明视图,则应学习 hitTest,否则只需添加手势或覆盖 touches 事件。
-
如果你不能全屏,你应该在当前窗口添加另一个透明视图来测试触摸,并覆盖方法'hitTest:withEvent:'
-
我有透明视图,即当我单击透明视图时它应该消失的父视图的大小。请提供代码的 sn-p
标签: ios objective-c touch-event