0

我有一个简单的 UIPopoverController 加载一个 Youtube 页面。一切正常,除了在其边界进行触摸时弹出框似乎随机关闭。

这似乎并不一致(关于哪些触摸导致解雇,尽管它从来不是第一个),有没有其他人看到过这种行为?

我在下面使用的代码,正在加载的 URL 仅用于测试。

-(void)showWebPopover
{
    UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WEBVIEW_POPOVER_WIDTH, WEBVIEW_POPOVER_HEIGHT)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://en.wikipedia.org/wiki/M"]]];
webView.backgroundColor = [UIColor blackColor];
//webView.scrollView.scrollEnabled = NO;

UIViewController *popOver = [[UIViewController alloc] init];
popOver.view.frame = CGRectMake(0, 0, WEBVIEW_POPOVER_WIDTH, WEBVIEW_POPOVER_HEIGHT);
popOver.view.backgroundColor = [UIColor blackColor];
popOver.contentSizeForViewInPopover = CGSizeMake(WEBVIEW_POPOVER_WIDTH, WEBVIEW_POPOVER_HEIGHT);
[popOver.view addSubview:webView];

self.webViewPopoverController = [[UIPopoverController alloc] initWithContentViewController:popOver];

CGRect rect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.width/2, 1, 1);
[self.webViewPopoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];
}
4

1 回答 1

0

可能为时已晚,但我只是遇到了这个问题并通过将 UITapGestureRecognizer 附加到视图控制器来解决它。(不是 PopoverController,而是 PopoverController 使用的控制器。)

IE

    func present (title:String, body:String, footer:String, sourceRect:CGRect) {
    if let fPopup = self.storyBoard.instantiateViewControllerWithIdentifier("GuideViewController") as? GuideViewController {
        popoverController = UIPopoverController(contentViewController: fPopup)
        fPopup.titleLabel.text = title
        fPopup.bodyTextField.text = body
        fPopup.footerLabel.text = footer

        //these 4 lines to set it up
        var touchRecognizer = UITapGestureRecognizer( target: self, action: Selector("handleTap:"))
        touchRecognizer.numberOfTapsRequired = 1
        touchRecognizer.numberOfTouchesRequired = 1
        fPopup.view.addGestureRecognizer(touchRecognizer)


        popoverController?.presentPopoverFromRect(sourceRect, inView: parentView, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
    }
}

func handleTap(sender: UITapGestureRecognizer) {
    if sender.state == .Ended {
        popoverController?.dismissPopoverAnimated(true)
    }
}
于 2014-07-22T23:23:25.323 回答