iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Iphone SDK通过点击它外面的ipad上关闭Modal ViewControllers大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想关闭一个FormSheetPresentation模式视图控制器,当用户轻按模态视图…我已经看到一堆应用程序这样做(例如在ipad的ebay),但我不知道如何,因为下面的视图被禁用触摸当模态视图显示为这样(他们将它作为一个popover也许?)…任何人有任何建议?

解决方法

我晚了一年,但这是相当直接。

你的模态视图控制器附加一个手势识别器到视图的窗口:

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@SELEctor(handleTapBehind:)];

[recognizer setnumberOfTapsrequired:1];
recognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
[self.view.window addGestureRecognizer:recognizer];
[recognizer release];

处理代码

- (void)handleTapBehind:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded)
     {
       CGPoint LOCATIOn = [sender LOCATIOnInView:nil]; //Passing nil gives us coordinates in the window

 //Then we convert the tap's LOCATIOn into the local view's coordinate system,and test to see if it's in or outside. If outside,dismiss the view.

        if (![self.view poinTinside:[self.view convertPoint:LOCATIOn fromView:self.view.window] withEvent:nil]) 
        {
           // Remove the recognizer first so it's view.window is valid.
          [self.view.window removeGestureRecognizer:sender];
          [self dismissModalViewControllerAnimated:YES];
        }
     }
}

就是这样。 HIG被诅,,这是一个有用的和经常直观的行为。

大佬总结

以上是大佬教程为你收集整理的Iphone SDK通过点击它外面的ipad上关闭Modal ViewControllers全部内容,希望文章能够帮你解决Iphone SDK通过点击它外面的ipad上关闭Modal ViewControllers所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。