小编mac*_*9_0的帖子

在外部点击iOS 8上关闭模式表单表视图

我一直试图在iOS 8的外部点击上忽略模态表单视图而没有运气,我试过这段代码

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];

- (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 …
Run Code Online (Sandbox Code Playgroud)

objective-c ipad ios

21
推荐指数
3
解决办法
8099
查看次数

标签 统计

ios ×1

ipad ×1

objective-c ×1