UIActionSheet does not prevent external, "under" touches - ios

I have a UIBarButtonItem in a navigation item that displays a UIActionSheet with a button to toggle a quick setting:
The action sheet is presented from the button item:
[calendarSettingsSheet showFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
However, here's the problem I'm encountering:
When I tap below the navigation bar, for example anywhere in the calendar, the UIActionSheet dismisses, which is expected. Any touch outside the sheet, in my opinion, should dismiss it.
But: I can still tap on the "Settings" and "Done" buttons in the navigation bar, and not only is the action sheet not dismissed, but the buttons function.
So, tapping "Settings" while the UIActionSheet is open, causes another to be opened. This can easily be avoided by checking to see if the action sheet is already open.
But, the "Done" button dismisses the entire calendar view, leaving the UIActionSheet hovering over the view that originally presented the calendar.
Is this intended behavior? While I could disable the buttons when the action sheet is presented, and enable them when it's dismissed, this seems like an unnecessary workaround.

Is this intended behavior?
Yes.
From the documentation of showFromBarButtonItem:animated:
On iPad, this method presents the action sheet in a popover and adds the toolbar that owns the button to the popover’s list of passthrough views. Thus, taps in the toolbar result in the action methods of the corresponding toolbar items being called. If you want the popover to be dismissed when a different toolbar item is tapped, you must implement that behavior in your action handler methods.

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.

Objective c - Create a tutorial bubble that will hide in background click

(First - i'm sorry about my english:).
I want to create a tutorial bubble that will pop up in some situations while using my app.
I need this popup to disappear when clicking or scrolling on every view in my VC, and i need that these buttons to do what they need to do in this click event and not only dismiss the pop up so then we will need to click on the buttons again.
I have 2 ways to do it, but every one of them have some disadvantage.
the popup view will have a transparent view with frame of the whole VC. this background view will dismiss the pop up in its touchBegin event.
but like that i can't click ob my buttons that below this popup background view.
the second option is to create the pop up without the background transparent background, so all the buttons will be clickable.
but in this situation i don't know how to listen all the buttons click event or table scroll event so i can dismiss the popup.

Popover controllers vs. the menu popover for SplitViewController

I use a floating popover to present suggestions in my UI. When the user wants to select an item from the menu bar in the splitview controller, the first tap just dismisses the popover. Therefore, the user has to tap twice, to activate a menu item.
If the user wants to activate the trash can, he has to tap it twice. Once to dismiss the other popover, and once to activate the trash can.
What's the best way to avoid this?
Wild guess here - but perhaps passThroughViews - add the button view and then in the button action, dismiss the popover (need to determine if it is active). A bit hacky but could work.

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.

Resources