In IOS 3.2 I was able to display my UISplitViewController side by side like in landscape mode.
In IOS 4.2 the RootViewController (MasterView) is not showing up in portrait mode. Does anyone know if we need to display the rootviewcontroll in a popover? Can we display it side by side like how it is in landscape mode?
I want to avoid having to click on a button to show the masterview (when in portrait mode)
In that case, you can skip the splitviewcontroller and create only view base application where you could manually control the UI.
on viewDidAppear you can do
[splitViewController setHidesMasterViewInPortrait:NO];
It works even though you get a warning. I think you can create category with a custom splitviewcontroller to get rid of the warning.
2.Otherwise you can do something like
on the viewWillAppear, you can do something like
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
UIViewController *master = [[splitViewController.viewControllers objectAtIndex:0];
UIViewController *detail = [[splitViewController.viewControllers objectAtIndex:1];
[splitViewController setupPortraitMode:master detail:detail];
}
(setupPortraitMode ) http://intensedebate.com/profiles/fgrios.
I used setHidesMasterViewInPortrait:NO and it did work on the pre-5.0 releases, and even got into the apple store once. But the next time I updated the app, they rejected it because I used a hidden API. I am still searching for a way to make this work.
Related
I have been trying to change the device orientation on a button click event for 2 days but I am not able to achieve it properly.
So, I have an iPhone app with a minimum version of 12.4, and the device that I am using to test is 14.4. I have used the code mentioned in this project here (which works properly when presenting a new view controller using push or present) but the same doesn't work when on the same view controller. The user needs to rotate his/her device to initiate the orientation change.
This is the code that I have in the view controller that I am trying to rotate on a button click event.
let appDelegate = AppDelegate.sharedInstance
let oldOrientaion = appDelegate.deviceOrientation
appDelegate.deviceOrientation = oldOrientaion == .landscapeRight ? .portrait : .landscapeRight
let value = appDelegate.deviceOrientation.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
Can someone please help me in figuring out what exactly is missing from this?
Also, on a side note, the view controller is presented on a different view controller so even if I try to present a new view controller like in the project for some time and change the orientation there it doesn't work.
Edit:
This is fixed now. I was trying to use the UIInterfaceOrientationMask to set the orientation instead of UIInterfaceOrientation. So changing the code to use UIInterfaceOrientation at the end works properly now.
Thanks for the help.
You are doing everything correctly, just need to call the attemptRotationToDeviceOrientation method to the oration change to take effect. Based on the documentation:
Some view controllers may want to use app-specific conditions to
determine what interface orientations are supported. If your view
controller does this, when those conditions change, your app should
call this class method. The system immediately attempts to rotate to
the new orientation.
In your code it will look like:
UIViewController.attemptRotationToDeviceOrientation()
I want to create an iOS app that can only work on landscape-view mode.
I Googled how to do that, and end up with supportedInterfaceOrientations method
Here's my attempt:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
I tried to put the above code on viewController.m and AppDelegate.m, but it didn't seem to work
Thanks, any opinion will be much appreciated
You don't need to write any code to run app which supports landscape mode only. Just select app target and uncheck portrait and portrait upside down orientation and make sure landscape orientation is checked.
It seems as though you want to programmatically change the orientation of your application. This can be done by any ViewController by implementing one method.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
That should force the view to auto-rotate in the direction you want it.
When you use -supportedInterfaceOrientationForPresentation it simply states that the returned interfaces can be used, not necessarily that they should be used.
When you use -preferredInterfaceOrientationForPresentation it says that this is orientation that I want, and that the ViewController should switch to it.
I would like to set different rules for the different viewControllers in my apps, not a single rule across all views (like you can define in Target-Summary).
For instance I have several views I would like my first few views to only appear in portrait view, however in my last view I would like the user to be able to change between protrait and landscape... I was woundering how I could do this.
Also I have read issues where the user navigates to a view while in landscape and the view appears landscape when it should be portrait and will not change untill the user rotates the device, I would like to avoid this if possible...
So my question is how can I allow different UIViewController Orientations depending on which view the user is in.
This will depend on whether you target iOS 5 or iOS 6.
iOS 5:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
if ((orientation == UIInterfaceOrientationPortrait) ||
(orientation == UIInterfaceOrientationLandscapeLeft))
return YES;
return NO;
}
iOS 6:
Set your default supported orientations in the App Summary and then in VC's you want to be different:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
Apple Documentation for this HERE
See these questions for more info:
shouldAutorotateToInterfaceOrientation not being called in iOS 6
shouldAutorotateToInterfaceOrientation is not working in iOS 6
I'm encountering an issue while using a webview. My app is currently a portrait application, but when a media player loads in a webview within my app, the user can rotate the player, which rotates my view controller as well. I know I can get a notification for when the player comes up and disappears, but is there a way to prevent it from rotating the controller in the first place?
It doesn't seem like anyone has an answer. I have all of the standard "don't rotate unless if I tell you to" methods and plist values, but its still rotating. Its only when I load up a webview and the media player loads over it. If I rotate my device, the media player rotates along with it, which feels natural, but when I go back to the webview view controller, its rotated, which isn't good.
Add this key in your info.plist :
UISupportedInterfaceOrientations and set it to UIInterfaceOrientationPortrait
Ok, this a blind shot. I've used this trick to force the system to adjust to the required orientation, add this lines when the webview will appears, or when the player will disappear:
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
Try in some of those methods, or in the didAppear or didDisappear if dosen't work. I know it look like rubbish, but sometimes works.
There doesn't seem to be a correct answer to this question.
I'm making an iPad application using a UISplitViewController. I want the masterView visible in a UIPopoverController when the app starts (and only when it starts) in portrait mode. If I use the presentPopoverFromBarButtonItem:permittedArrowDirections:animated: method in the splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
delegate function, I get the following error, when I start the app in portait mode:
Popovers cannot be presented from a view which does not have a window.
Can anybody help me?
The particular error says that you must add the view to a window before showing the popover, not the other way round. Try sending presentPopover… from the application delegate's -application:didFinishLaunchingWithOptions: after adding the view to your app's window.