In my app, While playing video user can play in full screen in both orientation landscape and portrait. But while move back to original position from full screen, i want to change my controller's orientation to portrait if its running in landscape.
Its working fine if i push that controller, but i have to present it. So its not working with presented controller.
I m using code as below to make it portrait.
[appdel.navigationController.presentedViewController.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
[[UIApplication sharedApplication].self.delegate.window addSubview:[appdel.navigationController.presentedViewController.view];
self.navigationController.navigationBar.hidden=NO;
Thanks for any help
see in case of presenting the controller when u come in previous controller the
viewWillApear: of previous method will call so change your orientation in viewWillApear: mthod
Related
I have two viewcontrollers, ViewControllerA supports both landscape and portrait, click a button in ViewControllerA push into ViewControllerB, which supports landscape only, then I make the phone in the landscape direction and then pop back to ViewControllerA, by default A is in landscape mode now, but I want it to be portrait first in this situation. How can I implement that?
In your ViewControllerA's viewwillappear method set the orientation like
[[UIDevice currentDevice]setOrientation:UIInterfaceOrientationPortrait];
I have added MPMoviePlayerController in my view. and its working fine. and when I switch to this in full screen and change the orientation of device then no orientation change event is fired. so please can let me know how I solve this issue.
Thanks
I suppose you present MPMoviePlayerController modally so check out the -
(void)shouldAutorotateToInterfaceOrientation: method of your main app controller. I suppose that if you return TRUE just for portrait the modal controller can't rotate itself. Try to return TRUE for all interface orientation on your rootViewController and the MPMoviePlayerController should start to rotate.
I am making an universal app, but only support rotation on iPad so here it goes:
I have a view that has a image as background. When the user rotates the iPad I fade this portrait image out in the willRotateToInterfaceOrientation and replaces the image with a landscape image in didRotateFromInterfaceOrientation, and this is working great! (If there are better ways I want to hear them, but this question is not about this though).
I have one button on this view that will push a new viewcontroller on the stack. This view controller also has the same "function" as the view that it was pushed from. What I need help with is: When I rotates the iPad from portrait (which was the orientation this view was pushed on from) to landscape the image in this "second" view changes as intended. However when I pop this viewcontroller off stack the "first" view still displays the image which is made for portrait and not the landscape one...I understand why but not how I should fix this.
Could anyone help me. Thank you for your time.
You can save the device orientation (check UIDevice documentation) on your viewWillDisappear: and check it on the viewWillAppear: method, calling the animation if necessary.
(the OP told me to post it as answer)
You could always register for UIDeviceOrientationDidChangeNotification and change the image if the controller is not on the top stack.
Assuming you're using a UINavigationController (since you mentioned pushing controllers), you could figure out if the controller is on top by:
if ([[self navigationController] topViewController] == self) {
// do magic
}
Use the first view controller's viewWillAppear method. In there, you can find the device's orientation by calling [[UIDevice currentDevice] orientation] and set the background image accordingly.
I have an application which is focused around a bunch of viewControllers in portraitmode, but on a specific detail view i need to open another view if the device is rotated to landscape mode.
So the user will look at the information view in portraitmode and if the user then rotates the device to landscapemode then a new view is displayed with additional information. If the user rotates back to portrait then the added view needs to be removed so the "original" detailview is visible.
It's important that the "original" detailview is not rotated to landscape - Only open a new view in landscape mode.
I've tried using shouldAutorotateToInterfaceOrientation: and managed to have it open a viewController, but it's not being shown in landscape view so it looks all messed up plus I'm having some trouble getting the view to disappear when i rotate back to portraitmode.
How do i do this?
Check if the orientation has changed using the View controllers did change orientation methods and if its rotated to landscape add ur landscape view and when the device is rotated to portrait remove the view from the view controller's view.
in shouldAutorotateToInterfaceOrientation
if(UIInterfaceOrientation == UIInterfaceOrientationPortrait){
NewView *newViewController = [[NewView alloc]initWithNib:#"NewView" bundle:nil];
[self.navigationController pushViewController:newViewController animated:NO];
}
you can repeat this for all the other orientations as well.
Using shouldAutoRotate didn't work since the view that gets opened will be opened in portraitmode and not landscape.
I ended up with a solution using beginGeneratingDeviceOrientationNotifications and shouldAutoRotate in the subview.
I have to present an alertview when my app starts. My app supports both landscape modes.
Despite the landscape mode the device is when the app starts the alertview always shows in portrait.
I have tried to use the accelerometer to detect the interface orientation before the orientation notification and I have the correct orientation 2 seconds before the alertview showing.
Then, I use this code to set the status bar to a different orientation, hoping the alertview will follow...
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
or left, depending on the landscape mode.
Nothing works.
Is there a way to force the alertview to respect the orientation?
The point here is this: I cannot set one landscape orientation in particular for the status bar, I have to detect the orientation the device is on and then set the status bar orientation.
thanks for any help.
Is your app using a UITabBarController or a UINavigationController?? Try calling the alert from the rootViewController , which may be a UITabBarController or any other rootController.
Dont show the alert from the immediate screen (or subview). Call [alert show] by overriding UITabBarController and from inside it.
i hope I got your problem right
Cheers,
Harikant Jammi