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.
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];
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
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.
Since iOS 3.2 the MPMoviePlayerController class allows to embed a movie in the view hierarchy.
Now I'm facing this issue: I create my portrait view by placing an instance of MPMoviePlayerController. When the user touch the "fullscreen" button this view enters in fullscreen mode but the view remains in portrait. When the user rotates the device the fullscreen movie view is not auto-rotated as my app forbids landscape interface orientation.
So in order to allow auto-rotation of movie player fullscreen view, I changed my view controller shouldAutorotateToInterfaceOrientation: method to return YES for landscape if - and only if - the movie player is in full screen mode.
This works perfectly: when the user enters in full screen and then rotates to landscape the player is auto-rotated to landscape and fills the entire screen.
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
return(YES);
}
if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return([movieController isFullscreen]);
}
return(NO);
}
Now the issue arises when I touch the "Done" button in the full screen view while remaining in landscape. The full screen closes and then what I see is my original view autorotated: but I don't want this auto-rotation.
A partial, but not acceptable solution, is to listen for "MPMoviePlayerDidExitFullscreenNotification" and, if the interface is rotated to landscape, force re-orientation to using the undocumented and private function:
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]
This works but is not acceptable as usage of this method is forbidden.
I tried to force orientation using [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait] but as I'm in a Tab Bar this doesn't work (the UITabBar remains Landscape-sized).
Thanks for your help
You can use a separate view controller for MPMovieplayer. You don't have to override the
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
in the original view controller.
if you are using MPMoviePlayerViewController, everything is already set nicely for you, as the method shouldAutorotateToInterfaceOrientation: will return YES by default. You can use it as a subview or present it modally by calling
presentMoviePlayerViewControllerAnimated:
Check this out: MPMoviewPlayerController fullscreen playback rotation with underlying UIViewController with portrait mode only (rotation disallowed)
Maybe a little different problem, but solution may be the same.
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