UIsplitview Not Respond Rotation - iphone

I am developing app using UISplitview.
When I am Rotate the device form Landscap to Portrait I set the frame but It is not set.
In portrait mode only detailview is there. Landscap mode master and detail view is there.
So how can i Identify rotation in portrait mode ?
is it any kind of method is there?(like In view controller has willAnimationRotationtoInterfaceorientation)

from what I understand, you want to be able to see the master in the portrait view.
The design of UISplitViewController specifically hides master view in portrait mode.
There are two ways to go about the situation here. First of all, you declare your ViewController controller as the UISplitViewControllerDelegate. (which view controller as the delegate? the one that stays in the stack - for you to figure out whether it's master or detail).
Then you have a few delegate methods to take a look at.
If you want to straight up just show the master in portrait mode in the following delegate method:
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
you return NO (aka you don't want it to hide the view controller)
By default, this is no for landscape, which is why you see both views, and yes for portrait, which is why you don't see the master.
Saying that, the more elegant solution would probably be to hide the master view and then put a button at the top of the navigation bar, after clicking on which, you will be shown the master in portait mode. And upon clicking outside the master view, the master will be hidden.
To do this, you do not use the above BOOL method, but implement these other two delegate methods instead:
– splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
– splitViewController:willShowViewController:invalidatingBarButtonItem:
Search documentation for UISplitViewControllerDelegate.

Make a new project in Xcode using the Master-Detail Application Template for iPad. This project template creates a UISplitViewController that responds to interface orientation. Thus it shows you fully and precisely how to do what you're asking to do.

Related

Swift 3 - UISplitViewController - Hide/Expand Master View in Landscape (e.g. Notes App)

Just started with Swift and would like to replicate some functionality present in the standard Apple 'Notes' app. Specifically the Expand button that appears in the Details View when on iPad in landscape mode.
i.e.
The closest I have come (as a simple quick solution) is to add the following into AppDelegate:
splitViewController.preferredDisplayMode = .primaryOverlay
However although this allows for toggling the Master View in landscape orientation (similar to the default portrait behaviour), it is done with the Master View as a popover/overlay. I however would prefer the behaviour present in the Notes app in that the Master View slides in/out (without overlaying the Detail View).
Edit: also interested in how to only show the corresponding button only in Landscape mode while on iPad.
Any help would be greatly appreciated! Thanks
splitViewController.preferredDisplayMode = .allVisible
This should do the trick. It makes the Master View slide in and out when toggling to fullscreen mode.

Interface Orientation Issue

I'm with a little problem. I have a TabBarController in my app, then one of the elements inside the tab bar is a navigation controller.
Well, inside my navigation controller, i want to play a video using web view.
My problem is: It's necessary to change the interface orientation of my web view. When i put a little bit of code, returning YES on the method shouldAutorotateToInterfaceOrientation (only for my web view's class), the video is still not changing the interface.
I've used a modal view controller to run my video, but we can see the same problem.
I don't have any idea about how to fix it, because i used all of my ios's knowledge.
Is there something to put inside my modal view controller to change my interface orientation?
My app has this kind of structure:
TabBarController->NavigationController ->VIew A->View B(Inside the View B, a ModalViewController)
Could someone help me?
If I understand correctly your question, you want to force the orientation of the device. This can be done by modifying the orientation of the status bar:
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];
For this to work, your app should be set so to support autorotation (returning YES from shouldAutorotateToInterfaceOrientation for all orientations); since you are using a navigation controller, also its root controller should return YES from shouldAutorotateToInterfaceOrientation.
You can call the above method when you need to switch orientation, i.e., at the moment you are going to play the video (when you load the web view, possibly).

Pushing portrait view controller onto landscape view controller?

I am trying to push a portrait only view controller onto a controller that allows portrait or landscape. The issue I'm having is that if the user is in landscape mode and I push the new controller on it will remain in landscape mode and just look all screwed up. How do I force the orientation to change to portrait as the new view controller is pushed on?
KDaker's answer is correct but another option you can think about is whether you can limit navigation when your orientation isn't what you want. This isn't necessarily a good idea but there are situations where it can work well. An example would be if you had a video which when rotated to landscape became full screen and covered your navigation back button until it returns to portrait.
in iOS 5 and anything before you cant 'force' an orientation from one view to another. You can support only one orientation for the project but then allow autorotation. So in your case, you can only allow autorotation and wait for the user to rotate the device.
In iOS 6, they have changed the way orientation handling works, and its become alot more flexible. You now have these methods:
- (NSUInteger)supportedInterfaceOrientations
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
Using these, you can present your view controller in any orientation you prefer, given that it is supported in the former method.
hope this helps.

Best practices for landscape only apps?

I'm a new iOS programming and I'm developing a simple iPhone game that needs to run in landscape only. I've ...
set supported orientations in the target settings
added the req. plist item (initial interface orientation)
overridden shouldAutorotateToInterfaceOrientation to return YES only for landscape modes
.. and the app "looks" correct, but there are a few odd things going on.
Issue 1 - I'm trying to manually position my views and not rely on autolayout. I've got a UIView in a NIB that I'm loading that needs to be positioned 150px from the right edge of the screen. I have to get the UIViewController's view's height (not width) to correctly position it - like it's not rotated to landscape at this point in the code.
Issue 2 - Implementing a UINavigationController to go from the title screen to the game interaction. When I'm pushing the interaction UIViewController to the stack, it slides in from the right like it's supposed to. When I go back to the title by popping the interaction, it slides UP to the title. It's seems like it's rotating back to portrait?
I think there is something very basic that I'm missing, but I can't find it in my app code. I've gone over the lists for a landscape app but they don't mention more than the list above.
Are there any other things/settings/methods to override that I should be on the look out for?
You need to set shouldAutorotateToInterfaceOrientation in your other viewControllers as well. Especially the ones displayed inside your UINavigationController.
Issue 2:
Don't use many UIViewController's. Use one view controller. Create one main UIViewController and for other UIViewController's just do:
[mainviewcontrl presentModalViewcontroller: child_viewcontrl animated: YES];
For delete a child view controller, use
[child_viewcontrl dismissModalViewControllerAnimated: YES];

How to force a screen orientation in specific view controllers?

My application is pretty simple: it starts up with a view controller that holds a table view (in grouped view layout) with a few options. When the user taps on one of the options, I push another view controller onto my navigation controller.
This second view controller simply displays a UIImageView, and the user can change the screen orientation on this view controller between portrait/landscape modes. This works just fine, and all is happy.
However, if the user taps on the "Back" button on my navigation bar while on the landscape mode, the first controller's layout is all messed up. See below for before/after screenshots:
(source: pessoal.org)
(source: pessoal.org)
Any clues on how to force the first view controller (second screenshot in this post) to stay within the portrait screen orientation?
There does not appear to be a way to do this using the documented methods.
I have filed a bug for this: rdar://6399924
"There is no way to always restrict a UIViewController to one orientation"
You can see it on open radar (along with a link to sample code to reproduce the problem) here: http://openradar.appspot.com/radar?id=697
Like someone on the open radar suggested, a workaround is to disable "back" button while in non-portrait:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
// don't let user press "back" button in landscape - otherwise previous view and the rest of the application
// will also be in landscape which we did not feel like testing yet
self.navigationController.navigationBarHidden = (UIInterfaceOrientationPortrait != self.interfaceOrientation);
}
There is a solution to do that : it's to use a view controller and adding its view to the window. then in that controller you force landscape in the shouldAutorotate... methode. It works fine, but be sure it's necessary for your project to use that, because it's not very smart  to force the user to turn his iPhone. By the way, here is an example code if you need it.
http://www.geckogeek.fr/iphone-forcer-le-mode-landscape-ou-portrait-en-cours-dexecution.html
I wasn't able to get this to work the way I wanted. You ought to be able to set a particular orientation for a ViewController, but the NavigationController doesn't seem to always do the right thing.
I ennded up re-designing my screens so that they all work in either orientation. That might be extra work, but it "feels" more natural, anyway.