从弹出的IOS7中删除UIview
在我的应用程序中,当用户单击按钮时,我将从弹出的IOS7中删除UIview,ios,uiview,dismiss,Ios,Uiview,Dismiss,在我的应用程序中,当用户单击按钮时,我将UIView显示为一个弹出窗口。现在的问题是,当用户单击应用程序中的某个位置时,它不会关闭。请告诉我如何关闭UIView弹出窗口 下面是用户用于弹出的代码 - (void) showPopView { self.popview.alpha = 1; [self.popview setFrame:CGRectMake(15, 100, 300, 300)]; //[self dismissPopoverAnimated:NO]; } 弹出
UIView
显示为一个弹出窗口。现在的问题是,当用户单击应用程序中的某个位置时,它不会关闭。请告诉我如何关闭UIView
弹出窗口
下面是用户用于弹出的代码
- (void) showPopView
{
self.popview.alpha = 1;
[self.popview setFrame:CGRectMake(15, 100, 300, 300)];
//[self dismissPopoverAnimated:NO];
}
弹出按钮代码
- (IBAction)click:(id)sender {
[self showPopView1];
}
在viewDidLoad
中,我使用了此代码
self.popview.alpha = 0;
上面的代码我曾经将UIView
显示为一个弹出窗口,请告诉我当用户点击外部时如何关闭弹出窗口
谢谢。在弹出视图的背景中添加自定义按钮(
ui按钮
)以隐藏弹出窗口。由于是自定义按钮,用户可以看到背景视图。确保按钮应该占据整个屏幕。当你显示弹出视图时,也会显示按钮,当用户隐藏弹出视图时,也会隐藏按钮,以便用户可以访问所有区域。这是最简单的方法。还有其他选项,如点击手势或检查触摸,但背景中的自定义按钮可以将风险降至最低。我要做的是在弹出窗口后面添加一个可触摸的覆盖
在你的
@interface YourController : UIViewController{
UIView *overlay;
}
在你看来,你没有加载
overlay = [[UIView alloc] initWithFrame:self.view.frame];
overlay.bakcgroundColor = [UIColor clearColor];
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap)];
[overlay addGestureRecognizer:singleFingerTap];
然后你的方法看起来像:
- (void) showPopView
{
[self.view addSubview:overlay];
self.popview.alpha = 1;
[self.popview setFrame:CGRectMake(15, 100, 300, 300)];
//[self dismissPopoverAnimated:NO];
}
- (void)handleSingleTap{
[overlay removeFromSuperview];
self.popview.alpha = 0;
[self.popview setFrame:CGRectZero];
}
我确实使用UIButton创建了一个演示,它正在工作,请检查下面的内容-
- (void)viewDidLoad
{
[super viewDidLoad];
backgroundButton = [[UIButton alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
[backgroundButton addTarget:self action:@selector(tapDetected) forControlEvents:UIControlEventTouchUpInside];
}
-(void)tapDetected
{
[backgroundButton removeFromSuperview];
[tempView removeFromSuperview];
}
-(void)showPopup /* on button click I created popup view as you already had */
{
[self.view addSubview:backgroundButton]; //Adding button to self.view
tempView = [[UIView alloc] initWithFrame:CGRectMake(15, 100, 300, 300)];
[tempView setBackgroundColor:[UIColor redColor]];
[backgroundButton addSubview:tempView]; //Adding popup view to button.
[tempView setAlpha:1];
}
请告诉我在哪里我必须声明这个覆盖显示错误我刚刚编辑了我的答案,它可能是在您的.h.中声明的ivar。它显示为未声明的选择器“handleSingleTap”,如下所示。它显示请告诉我如何解决此问题。您是否在同一控制器中添加了下面的方法handleSingleTap?不,我没有在控制器中添加任何方法handleSingleTap