Prevent popovers from displaying over presented views - ios

I am attempting to display a passcode screen that appears after X amount of inactivity. I use presentViewController:animated:completion: on the root view controller, and it works as expected, except when a popover is already being displayed. The popover, displayed from a bar button item, appears over the presented passcode screen.
Is there a way to dismiss or hide all visible popovers when presenting a view controller?

Create and add a 2nd window over the first. Present the passcode screen in the 2nd window. This will allow it to appear over any and all views from the first window. When you dismiss the passcode screen, be sure to remove the new window and make the 1st one key again.

Do you have a reference to the popover? Then you can just call
[popover dismissPopoverAnimated:NO];
when you go to shop the passcode overlay.
EDIT
Looping through subviews and seeing if you can dimiss a popover. I'd really recommend trying to find some other way of doing things as this is just icky. But it should work (untested).
for (UIView* view in self.view.subviews) {
if([view respondsToSelector:#selector(dismissPopoverAnimated:)]){
[(UIPopoverController*)view dismissPopoverAnimated:NO];
}
}

NSNotifications are a good tool for this problem. Have all your views or controllers that present popovers listen for a notification named, say, WillPresentPasscodeScreen, and implement a method that dismisses the popover when the notification comes in. Then, before you present your passcode VC, post a WillPresentPasscodeScreen notification -- no more popovers, regardless of where you are in the app.

Related

Possible to dismiss a UIPopoverController on a drag action

I have some UITouch drag activity going on in the main view / controller that invokes a UIPopoverController. Surprisingly, the popover isn't dismissed when the user drags on the invoking view, though a single tap does dismiss it.
Does anyone know how to force a popover dismiss on a view drag? The view's touch events do not seem to be received, so my best guess is looking at the application's view events and try to figure out drags from there, but I'm not sure.
When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the
passthroughViews
property. Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the
dismiss(animated:)
method as needed.
Docs: https://developer.apple.com/documentation/uikit/uipopovercontroller

Should I dismiss keyboard before dismissing the view?

I have two UIViewControllers, on modally presented over the other. The first controller is orientated in landscape, and the modal view is presented in portrait.
When dismissing the modal view, the view animates to reveal the landscape view below. If the keyboard is visible on the modal view at this time, it will suddenly attach itself to the left or right side of the screen to match the orientation of the soon-to-be active viewController.
Is there a way to let the keyboard disappear in the same orientation as the disappearing viewController? Or should I perhaps dismiss the keyboard before dismissing the modal view controller? In that case, what would be the best approach?
I do have an action for when the user clicks 'close'. I can there check if any objects are firstResponder, and start a timer for ~0.4 seconds before dismissing.. But it would obviously create a kind of delay that wouldn't feel all that natural.. I'd prefer a way to let the keyboard stay attached to the same orientation as the dismissing view.
This is happening:
I think the best practice would be to dismiss the keyboard before dismissing your modal ViewController. The keyboard is presented over your content and should be removed first before removing other items in the view hierarchy.

pop view controller with enabled/open keyboard in ios 8

i am trying to implement some chatroom-like view controller (e.g. Messages-app on iPhone), and i would like to keep the keyboard enabled/open when this (chatroom-like) view controller gets dismissed and therefore gets popped from the stack, BUT dismiss it together with the view, i.e. sliding it out of the screen together with the chatroom-view-controller.
For the desired effect, just open the Messages-app on the iPhone, go into one chatroom/conversation, set the focus on the input-textfield so that the keyboard comes up, but then go back to the last view without dismissing the keyboard.
I always get this weird animation that the chatroom-view (-controller) is sliding out of the screen to the right (which is desired), but the keyboard gets dismissed to the bottom of the screen...
Does anyone know what I am doing wrong? I have already tried it with so many versions, from become/resign first responder in all the different view will/did appears...
My assumption is that it could have something to do with my custom pan gesture recognizer for popping the chatroom-view-controller from the stack of the navigation controller, but neither the docs nor the web contain such issues...
you don't need to keep your keyboard visible, instead you can make snapshot of chatroom controller right before it being dismissed.
Edit: I just created simple app with navigation controller which pushed controller contains text field. Then on app tried to pop that controller when keyboard is visible. And..all view was dismissed together with keyboard, so your wanted behaviour is given by default.

Laucning View from UIAlertView, and when new View Dismissed want original AlertView still visible

I am using UIAlertView to let the user know some information, I have a button on the AlertView that when clicked triggers a whole new view to be shown.
The pseudo code run when the button is clicked is:
Find my UIViewController, and initiate the veiw controller for my new view, and call presentModalViewController:mySecondView animated:Yes
And this works fine..
On mySecondView I have a button that I use to dismiss the view using dismissModalViewControllerAnimated:YES
Now, the transitions work, I click on the UIAlertView Button and the SecondView appears, and when I click on the Exit Button my original View appears, unfortunately it appears without the ALERTVIEW that started the transition..
I want the first view to reappear with the AlertView still visible, after all the user did not dismiss it. So, what is the best way to go about this? Have the button simply load the veiw from a nib, and add it to the subview of the parentview of alertview, and then hide it when the exit button is pushed? Seems kludgy and boring, but I assume this would work...
Store the fact the alert view is visible in a modal variable, and on the ViewWillAppear check the modal, and then redraw the UIALERTVIEW? This seems like a memory leak to me, since the original view was never explicitly released...
I got to believe there is a more elegant solution... any ideas anyone?
Well, in the end I just wound up just recreating the alert view after the secondary view was dismissed. I can't say I'm crazy about it, but it does provide the behavior I need without lots of hacking.

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.

Resources