如何在视图外部点击iPad上关闭popover View控制器:IOS 9

时间:2016-04-27 10:21:29

标签: ios swift ipad ios9 uigesturerecognizer

我试图使用类型为.pagesheet的模式样式将视图控制器呈现为popoverviewcontroller。在这里,我试图添加一个轻敲手势识别器来点击这个popoverviewcontroller点击其视图。但它没有在iOS 9中检测到点击。以下是手势识别器的代码

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let recog : UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action:#selector(HandleTap))
        recog.numberOfTapsRequired = 1
        recog.numberOfTouchesRequired = 1
        recog.cancelsTouchesInView = false
        recog.delegate = self
        self.view.window?.addGestureRecognizer(recog)

    }


func HandleTap(sender:UITapGestureRecognizer) -> Void
{
    if(sender.state == UIGestureRecognizerState.Ended)
    {
        var location : CGPoint = sender.locationInView(self.presentingViewController?.view)
        //var location : CGPoint = sender.locationInView(self.view?.window)
        if(!(self.view.pointInside(self.view.convertPoint(location, toView: self.view?.window), withEvent: nil)))
        {
          self.view.window?.removeGestureRecognizer(sender)
          self.dismissViewControllerAnimated(true, completion: nil)
        }
    }
}

1 个答案:

答案 0 :(得分:1)

long expiration = 0L; if (!producer.getDisableMessageTimestamp()) { long timeStamp = System.currentTimeMillis(); message.setJMSTimestamp(timeStamp); if (timeToLive > 0) { expiration = timeToLive + timeStamp; } } message.setJMSExpiration(expiration); //me: timeToLive coming from default values of Producer/JmsTemplate... 设置为您处理点按的userinteractionenable上的true。第二件事你为什么在view做你的东西?您应该使用viewDidAppear添加手势识别器。

更新:

viewDidLoad

如果您使用导航控制器,那么<​​/ p>

self.view.window?.userInteractionEnabled = true

希望这会有所帮助:)