简体   繁体   English

PopOverView打开时如何启用外部触摸?

[英]How to enable touch outside when PopOverView open?

I'm using popover with my app. 我在我的应用程序中使用了popover。 I want to enable touch outside when popoverview open. 我想在popoverview打开时启用外部触摸。 For now I can not touch outside of popoverview when i click the outside of popoverview , it disappear. 现在,当我单击popoverview的外部时,我无法触摸popoverview的外部,它消失了。

Here is my screen shot for what i want to do. 这是我想做什么的屏幕截图。 I use popoversegue in storyboard. 我在情节提要中使用popoversegue。

How can i do this issue? 我该怎么办?

Thanks for helpings. 感谢您的帮助。

在此处输入图片说明

You can use the passthroughViews for achieving the same. 您可以使用passthroughViews实现相同的目的。

yourPopoverController.passthroughViews = [NSArray arrayWithObjects:viewToEnableTouch, nil];

passthroughViews Property passthroughViews 属性

An array of views that the user can interact with while the popover is visible. 弹出窗口可见时用户可以与之交互的视图数组。 Declaration 宣言

Swift 迅速

var passthroughViews: [AnyObject]?

Objective-C 目标C

@property(nonatomic, copy) NSArray *passthroughViews

Discussion 讨论区

When a popover is active, interactions with other views are normally disabled until the popover is dismissed. 当弹出框处于活动状态时,通常会禁用与其他视图的交互,直到关闭弹出框。 Assigning an array of views to this property allows taps outside of the popover to be handled by the corresponding views. 通过为该属性分配视图数组,可以由相应的视图处理弹出窗口之外的点击。 Import Statement 进口声明

import UIKit 导入UIKit

Availability 可用性

Available in iOS 3.2 and later. 在iOS 3.2和更高版本中可用。

Reference UIPopoverController Class Reference 参考UIPopoverController类参考


If you don't want to dismiss popover when user clicks outside, then you can achieve that through: 如果您不想在用户单击外部时消除弹出窗口,则可以通过以下方法实现:

- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
    return NO;
}

Here is what worked for me using SWIFT. 这是使用SWIFT对我有用的。 It will allow you to interact with the "doneBtn" as well "myMap". 它将允许您与“ doneBtn”以及“ myMap”进行交互。

@IBOutlet weak var myMap: MKMapView!

func showPopover() {

    let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    var popOverVC: popVC = storyboard.instantiateViewControllerWithIdentifier("popVC") as popVC

    popOverVC.modalPresentationStyle = .Popover
    popOverVC.preferredContentSize = CGSizeMake(self.myMap.frame.width, self.myMap.frame.height)

    if let pop = popOverVC.popoverPresentationController {

        var passthroughViews: [AnyObject]?
        passthroughViews = [doneBtn, myMap]
        pop.passthroughViews = NSMutableArray(array: passthroughViews!)

        pop.permittedArrowDirections = .Any
        pop.sourceView = myButton

        pop.delegate = self

        pop.sourceRect = CGRect(
            x: 0,
            y: 0,
            width: 10,
            height: 10)
        }

    self.presentViewController(
        popOverVC,
        animated: true,
        completion: nil)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM