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.
You can use the passthroughViews
for achieving the same.
yourPopoverController.passthroughViews = [NSArray arrayWithObjects:viewToEnableTouch, nil];
passthroughViews
PropertyAn 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;
}
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With