Popover presenting underneath modal - ios

I have a modal view controller that gets presented on iPad. Inside that modal I have a UIPopoverController that is presented to the user (triggered by a button press). What's crazy is that the popover is getting instantiated and rendered, but directly underneath the modal. I am presenting from a UIBarButtonItem, so there shouldn't be any view hierarchy issues on where it should be presented from. Doing a recursiveDescription on the window reveals that the view hierarchy is correct with the popover being on top, despite it visually being drawn underneath.
Any thoughts in what could be causing this? How do I fix it?
Update: I decided to try presenting a form sheet modal on the modal and experienced the same problem: the form sheet modal is rendered underneath the first modal. Truly puzzling...

After a night's sleep I instantly discovered the problem:
destination.view.layer.zPosition = 1000;
Because I am doing some 3D affine transforms in the animation, I needed to raise the zPosition of the destination view's layer so that it doesn't clip the source view's layer when rotating. I was forgetting to change the zPosition back to 0 when it completes.

Related

Unable to set a dim background to a modal view

I'm developing an app targeting iOS 7 and above. I'd like to present modally a view with a dim background that partially shows the previous view below. I've read several posts dealing with this scenario, and I did:
Created a view controller scene in storyboard and set a modal segue to navigate to it.
Set the Presentation value of that modal segue to Current Context.
Set the view controller's view background color to clear color.
Added a full-screen view above the parent view, with black color background and 50% opacity.
Transition to the modal view is default and animated. While the animation, I see the view being presented as semi-transparent, but once the transition animation ends and view finally occupies the full screen, the view becomes opaque black.
What I'm doing wrong? How could I solve this?
As #luk2302 said, when you present a view controller modally, iOS removes the view controllers underneath it from the view hierarchy so is nothing underneath it except the app window, which is black. Anyway, iOS 7 has a new modal presentation style, UIModalPresentationCustom, that forces iOS not to remove the views underneath the presented view controller. But you must provide your own transition delegate to handle the presentation and dismiss animations
Check this link how to implement custom transition delegate.

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.

Segue Modal transition removes source controller

I have a simple structure hooked up in Storyboard. I want to transition from one scene to another using a Modal transition. The scene where I am transitioning to is smaller then the current scene. So I want the "bounds" of the current scene to be visible behind the modal view.
But when I transition, and the transition is completed, the source view controller is removed from screen. Leaving black surroundings behind.
I have made a short video with the problem. Which can be found here. How can I make it so with the segue that the source view controller stays on screen?
Well, found the solution. In those duplicates people state it cannot be done except when you use a screenshot as "background".
But setting this:
source.modalPresentationStyle = UIModalPresentationCurrentContext;
on the source controller seems to work. Then it does not disappear.

don't want the modal view to move up on keyboard show

I have a viewcontroller from here I am getting a popover. From this popover i am presenting a view as modal view.
There is a textview in it. When editing begins, the entire modal view moves up (which usually people desire). But I do not want it that way.
Is there any way, i can block my modal view from moving up and down on keyboard show and hide ?
If I guessed correctly then you need to set
yourviewControler.modalPresentationStyle=UIModalPresentationPageSheet;
instead of what you are probably using right now
yourviewControler.modalPresentationStyle=UIModalPresentationFormSheet;

iPad modal form sheet takes up the whole screen anyways

I'm trying to create a form sheet modal on iPad, which should be a 540x620 modal view.
I've created a view controller with a NIB file whose view is a 540x620 sized UIView (with stuff on it).
I set the modal presentation style to UIModalPresentationFormSheet, and call presentModalViewController:animated: on the current view controller.
My view slides in from the bottom, but instead of being a form sheet, it takes up the whole screen (my view elements are all anchored in the top left of the screen).
Even stranger, when I dismiss it, all the UI that was "underneath" it, is all re-layed out to be in the center, in approximately a form sheet sized area in the center of the screen. Bizarro!
Anyone have any suggestions as to what could cause this behavior?
Thanks.
Figured this out. I was setting the modal presentation style on the parent view controller-- it needs to be set on the newly-created child controller. One needs to think of it as a property of the child, not something the parent controls.
I would delete this question, but figure I'll leave it as a signpost for the future wayward.

Resources