以下是它现在如何工作的示例.这是link to the Code.
第一种方法:
您可以为按钮和其他视图设置一个标签,这些视图不希望在敲击菜单时将其关闭:
button.tag=99;button2.tag=99;backgroundImage.tag=99;
然后在vIEwcontroller中,使用touchesBegan:withEvent:delegate
-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UItouch *touch = [touches anyObject]; if(touch.vIEw.tag!=99){ //Call your dismiss method }}
第二种方法:
如果您的按钮有一个叠加层(例如突出显示按钮的背景,并填满整个视图),您可以为其添加UITapGestureRecognizer,并在每次希望显示自定义视图时将其添加到视图中.这是一个例子:
UIVIEw *overlay;-(voID)addOverlay{ //Add the overlay,if there's one in your code,then you don't have to create this overlay = [[UIVIEw alloc] initWithFrame:CGRectMake(0,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height)]; [overlay setBackgroundcolor:[UIcolor colorWithRed:0 green:0 blue:0 Alpha:0.5]]; //Register the tap gesture recognizer UITapGestureRecognizer *overlayTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onOverlayTapped)]; [overlay addGestureRecognizer:overlayTap]; [self.vIEw addSubvIEw:overlay];}- (voID)onOverlayTapped{ //Call your dismiss method for (UITapGestureRecognizer *ges in prevIEwOverlay.gestureRecognizers) { [overlay removeGestureRecognizer:ges]; } [overlay removeFromSupervIEw];}
你可以在这里看到类似案例的my answer.
总结以上是内存溢出为你收集整理的如果点击iOS屏幕上的其他位置,则会关闭菜单?全部内容,希望文章能够帮你解决如果点击iOS屏幕上的其他位置,则会关闭菜单?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)