Get Bounds after tap outside from a UIPopoverController - ios

Imagine a ViewController with 2 UITextFields. When you tap on TextField1, it appears a Popover.
Now, if I tap out of the popover, it disappears (OK). However, I want this behaviour:
If I click outside of the popover, and this tap is on TextField2, I want to dismiss the popover (OK), AND throw an event (for example, open other popover from TextField2).
I've tried this solution: Iphone SDK dismissing Modal ViewControllers on ipad by clicking outside of it
But handleTapBehind method doesn't execute if popover is visible.
Is it possible?
Thanks!

you should implement UIPopoverControllerDelegate
and use
popoverControllerShouldDismissPopover:
popoverControllerDidDismissPopover:
see More for details

Related

How to avoid having two UIPopoverPresentationControllers up at same time each from UIBarButtonItem in UItoolBar

I'm in the process of converting an old iOS app which uses UIPopoverController to the new UIPopoverPresentationController. I have two popovers (A & B) each initiated from a click on a UIBarButtonItem (butA, butB) in a UIToolBar. I have the popovers each displaying fine. If I click in the main view the popovers disappear correctly.
If I press butA popover A appears. If I then press butB nothing happens. In this case, the popover controller B was being presented from the UIBarButtonItem (butB).
If I present the popovers from a sourceRect near butA and butB, I get a slightly different result. Click on butA and popover A appears. Click on butB popover A disappears. Click on butB a second time, then popover B appears.
How can I get this to work correctly, with popover A disappearing when I single click on butB? I have tried to dismiss ViewController A as part of the butB press action, but the ViewController A object at that point is nil.
Any help would be appreciated.

Dismiss iOS form sheet modal via outside tap + VoiceOver mode

On an iPad, you can use controller.modalPresentationStyle = UIModalPresentationFormSheet to show a centered modal on the screen. A common technique is to allow the user to dismiss the modal by clicking "outside" or "behind" it. This is covered in numerous other answers (Iphone SDK dismissing Modal ViewControllers on ipad by clicking outside of it,
Dismiss modal view form sheet controller on outside tap), usually by adding a tap gesture to the view's UIWindow.
My question is, how do I make this accessible to users in VoiceOver mode? The native action sheets allow clicks outside the sheet to dismiss, and even prompt the user, saying "double tap to dismiss popup window". How can I expose the UIWindow tap gesture in the same way?
From Apple:
https://support.apple.com/guide/iphone/learn-voiceover-gestures-iph3e2e2281/ios
Dismiss an alert or return to the previous screen: Two-finger scrub
(move two fingers back and forth three times quickly, making a ā€œzā€).
If the modal sheet is opened, we can prompt the user to "make a z gesture" to go back.
There is basically no way to do this with the FormSheet presentation. You can use the Popover presentation, but it behaves differently in some cases.
My solution was to check UIAccessibilityIsVoiceOverRunning() and add an extra close button element to the top of FormSheet that can be clicked via voiceover. I also implemented accessibilityPerformEscape for the global escape gesture.

iOS Segues with Popover has undesirable default behavior

I've got a weird issue with segues - I have a segue open a popover when a UIButton is tapped, all of this done through IB. (This is on iPad)
But when I select an option from the Tableview on this popover I want it to dismiss the popover. And I don't want the popover to open twice if the user taps that UIButton twice..
The way things work by default, tapping that UIButton keeps opening popovers on top of each other "forever" and also I still have the issue that when a cell from my Tableview is tapped, the popover remains.
How can I solve these problems?
Use prepareForSegue: method to dismiss the pop over if it is already present.
Here is given, how to use that method.
Prevent multiple popovers:
Use an if statement to determine whether a popover is present or not, if it isn't present it, if it is don't.
Dismiss on cell tap:
In didSelectRowAtIndexPath call dismissPopover on your popover view.

Pass touch to underlaying button of UIPopoverController

I've got a modal view that has "Cancel" button (the button dismisses modal).
In the modal, I'm shoving a small UIPopover.
What I'm trying to achieve is:
When the UIPopover is visible, if uset touches "Cancel" it will do both:
hide popover (it's happening now, since that's the click outside popup)
hide modal - as if user touched "Cancel" without popup
Is there a way to do it?
UIPopoverControllerDelegate is not providing any help (or I'm not seeing it :) )
Thanks :)
Before presenting the popover, add the Cancel button to the popover's passthroughViews array:
popoverController.passthroughViews = [NSArray arrayWithObject:cancelButton];
This will let the Cancel button respond to touches while the popover is displayed without automatically dismissing the popover.
Then in your Cancel button's action method, call dismissPopoverAnimated: on the popover before dismissing the modal view.
You'll need to keep a reference to the popover in an ivar (eg. popoverController) to do this.

iPad Popover containing an UIWebView will not dismiss if ever touched inside webview

I have a UIWebView inside a popover.
As long as I never tap (scroll, etc) the webview all is fine. That is, if I tap anywhere on the screen outside of the popover the popover is dismissed.
However, if I tap (scroll, etc) inside the webview, then tapping outside of the popover fails to dismiss the popover.
this was fixed by the gold master of 4.3

Resources