Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable touch outside when PopOverView open?

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

like image 555
fozoglu Avatar asked Jan 27 '15 08:01

fozoglu


2 Answers

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;
}
like image 180
Midhun MP Avatar answered Nov 15 '22 03:11

Midhun MP


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)
}
like image 33
the_pantless_coder Avatar answered Nov 15 '22 05:11

the_pantless_coder