Is it even possible to disable rotation when the View Controller I want to disable it in is
in a Navigation Controller that supports all directions? for one special view I want only portrait mode to be allowed, I´v tried about everything but nothing seems to work - I am guessing this is cause the View Controller is part of a Navigation Controller with segues?
By Default any property or a setting of a Super View is applied on all the sub-views inside it. Therefore even if you block the View Controller it will rotate because it is in Navigation Controller that allows rotation. Therefore i would suggest that you create a property in your AppDelegate that sets the orientation settings and then haldle it from ViewControllers
Related
When performing a custom modal view controller transition, the view controller you're coming from sits behind the new one nicely (think of Apple's "form sheet" style presentation on an iPad for instance), and when you rotate the device the previous view controller visible in the back rotates as well.
I'm unsure how to get this functionality with a UINavigationController custom push animation. It seems it isn't expected for the previous view controller to be visible from behind and it isn't.
I could take a screenshot, but it won't update on landscape rotation.
How is it done so easily with a modal transition and how do I replicate that for navigation controller custom transitions?
As far as I understand the UINavigationController class such functionality cannot be achieved through it.
UINavigationController is a container controller, which can show only one VC within it at a time. It keeps all the VCs in the stack, but not their views (views are kept by VCs themselves).
Unlike it, the modal presentation is a special type of VC-presentation, and it's not limited by the container-functionality.
I'm having trouble popping a UINavigationController (subclass) from a landscape view to a portrait view.
I have a chain set up from the window's rootViewController using shouldAutorotate and supportedInterfaceOrientations down to the individual View Controllers that I present.
So, I have a View Controller that ONLY supports portrait. The next one that is pushed supports landscape as well.
When I push the one that supports landscape and then rotate the device, everything rotates. So far, so good.
Now, when I pop back to the first one, both views rotate BEFORE the animation. So, the second viewController's landscape view (which is really small because of the rotation transform) is pushed away to the right side of the portrait screen.
I want the landscape view to be pushed away to its right (the top or bottom of the portrait view controller), while the portrait view controller is shown in the background.
How can I accomplish this?
I thought I might try to use an animation controller, but the UINavigationController's delegate method, navigationController:animationControllerForOperation: isn't called when popping to a View Controller in a different orientation.
After days of experimentation I figured out what my problem was. Hopefully this will help someone in the future.
I was trying to over-engineer the chain.
I had a custom container with a child tab bar controller which contained multiple navigation controllers that contained view controllers with different orientation requirements.
My main downfall was assuming that even if a modal window was presented, the system would still ask the window's root view controller first. To account for this situation I added a check in the container that looked like this:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if (self.presentedViewController) { // This check is wrong! Don't do this!
return [self.presentedViewController supportedInterfaceOrientations];
}
// Pass request to child view controller
}
However, this was fundamentally causing my problem in two ways.
First, without this check, UIKit will automatically detect the modal view controller and directly ask for its supportedInterfaceOrientations.
Second, the way UIKit handles the animations involves presenting several internal view controllers that we normally would have no idea are there. By checking for a modal view controller in presentingViewController, the check was catching them and asking them all for their supportedInterfaceOrientations. UIKit isn't meant to behave this way, so I was the one interfering with its operations.
The fix was to implement supportedInterfaceOrientations so that it ONLY concerns the view controller's direct descendants (i.e. the view controllers whose views are descendants in the current view controller's view hierarchy). The direct descendants can further pass the request down from there.
Treat modal windows as a completely separate chain, regardless of the presenter.
In other words, trust UIKit.
I would like to have custom view set in one screen and have it across all view controllers in my application.
I find solution with using Container view. So I create RootViewController and I give it Container view and set my original MainViewController as embed in container. I added view to RootViewController and in first view controller (MainViewController) it looks good.
The problem is when I go to another view controller by Push segue. New view controllers covers whole screen (which is okay) and covers custom view too. I was thinking that it could help if I add Navigation Controller with root MainViewController and this navigation controller would be embed in RootViewController but the result is same. I set Navigation bar as hidden (same for status bar) because I want to be hidden.
So where could be problem? Or how would you add custom view to all screens? This custom view should work as global (I am using NSTimer and counting time) so I solution with inheritance isn't for me.
You can use application window and add this custom view as subview whenever required. I have used it in one of my app to show notifications (if there area any) and it works great.
Get handle to Application Window and add subview to it. Custom view can be created from a singleton class or App delegate.
You could try it the other way round. Make a view which will never change inside your root view controller and a container view and just change the content of the container view depending what u want to display next to your unchanging view.
I'm working on an app that uses a UITabBarController, where each tab contains a UINavigationController stack.
I'm attempting to create a UIDynamicAnimator that will use UIDynamicBehaviors to animate in, from the top, a UIView from under the UINavigationBar, such that it collides with the UITabBarController's UITabBar and pushes it off the screen.
In order to achieve this, my reference view for the UIDynamicAnimator must contain the UITabBarController's view.
Is it okay to use the UIWindow instance as the reference view for the UIDynamicAnimator?
(Please provide feedback on this approach as well, I see others modifying the frame of UITabBarController.tabBar - is that bad practice?)
Any view will do. All you are doing is setting the frame of reference.
Be aware, however, that the window does not rotate when the device rotates (window coordinates are screen coordinates, and are fixed with respect to the device). Thus, working with its coordinates can be a nightmare.
Given the nature of your question, since everything is happening inside the tab bar controller, I don't see why you don't use the tab bar controller's view. It contains the tab bar and the various views of the child view controllers. If it is the root view controller (as I suspect it is), it contains absolutely everything else, and it itself is not going anywhere.
Interface builder does not allow you to add a UISplitViewController as the root controller of a UINavigationController.
I've also tried programmatically creating the UINavigationController and setting its root view controller to be the UISplitViewController.
The result is an empty window with just the nav bar.
I've also tried a split view controller replacement, MGSplitViewController. It mostly works, except that within the split view controller, the master view is another UINavigationController. Its nav bar shows up too thick. Changing orientation and back clears it up.
I've been trying all sorts of different approaches to having a view that looks like a split view and other views that I switch between. I've tried within a tab view controller, writing my own controller to manage subviews of the window and having the split view as a managed view, and now the navigation controller. All attempts have had some issues. The most consistent issue is regarding the orientation of the view. My app is running in landscape mode and typically the child views think its still portrait.
Any ideas appreciated.
No.
The bottom line: a UISplitViewController must be the root view of an app (or perhaps more specifically, a window). It can not live inside a UINavigationController or anything else.
This is the case with the current SDK, and there's no guarantee that will change in future SDKs.
It seems strange to add a split view to a navigation stack. The master pane of a split view controller is generally a navigation controller, so (without knowing more about your design), I'd probably use that to control your navigation hierarchy.