How to enable touch outside when PopOverView open?
Asked Answered
S

2

7

I'm using popover with my app. I want to enable touch outside when popoverview open. For now I can not touch outside of popoverview when i click the outside of popoverview , it disappear.

Here is my screen shot for what i want to do. I use popoversegue in storyboard.

How can i do this issue?

Thanks for helpings.

enter image description here

Sayce answered 27/1, 2015 at 8:43 Comment(0)
C
6

You can use the passthroughViews for achieving the same.

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

passthroughViews Property

An array of views that the user can interact with while the popover is visible. Declaration

Swift

var passthroughViews: [AnyObject]?

Objective-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

Availability

Available in iOS 3.2 and later.

Reference UIPopoverController Class Reference


If you don't want to dismiss popover when user clicks outside, then you can achieve that through:

- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
    return NO;
}
Carnage answered 27/1, 2015 at 8:49 Comment(5)
thanks.it will do my stuff but i don't have popovercontroller class. i use popoversegue. How to import this code my project.Sayce
@fozoglu: In the prepare for segue you can get it like : UIPopoverController* popover = [(UIStoryboardPopoverSegue*)segue popoverController];Carnage
i get a error viewToEnableTouch -> use of undeclared identifierSayce
@fozoglu: That's a dummy value I put. You need to put your actual view there (something like self.view)Carnage
Sorry. I am confused. I create simple project. i add two button in storyboard and just one button connect popoversegue. i create two UIViewController class first ViewController second MyPopoverController. Import MyPopoverController in ViewController Here then what should I do ?Sayce
G
3

Here is what worked for me using SWIFT. It will allow you to interact with the "doneBtn" as well "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)
}
Giuditta answered 6/5, 2015 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.