I have an app that support only portrait mode, but I have an NowPlayingViewController with youtubeView.
I want only this youtubeView support landscape mode (when it's fullscreen)
I found this (in appdelegate.m)
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[self.window.subviews.lastObject class].description isEqualToString:#"<string>"]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
but I don't know how to set description to my youtubeWiew with this string.
Anyone has solutions?
Rotation has become bit tricky as you can't rotate it forcefully. Though there is a solution, is you need to Customize UINavigationController to add Landscape Rotation, and then present the extra view as modal, it will work.
For more clarification see a sample here I have made for rotations.
I hope it will help you and others.
Cheers.
Related
For the app, the orientation is in portrait most of the time, but we have one view that needs to be set to landscape. I have this code to set it to landscape:
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
I also have device orientation set to portrait and landscape left in the general tab for the app.
The issue is that the app will sometimes work properly but other times it will get stuck in a mix between portrait and landscape.
I have provided an image of what it looks like getting Stuck in transition. If I then reload the view it will work properly, it is only on the first time opening the view that it has a chance of failing.
I think you should set this in AppDelegate.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
if self.rotatble {
return UIInterfaceOrientationMaskLandscape
} else {
return UIInterfaceOrientationMaskPortrait
}
I have an iOs project that needs to support all orientations on iPad and on iPhone I need to support only portrait on all view controllers EXCEPT one that needs to support all orientations and autorotate.
I tried:
#pragma mark - Should Rotate device
- (NSUInteger)supportedInterfaceOrientations
{
if ([[DeviceInfo sharedInstance] is_iPhone]) {
return UIInterfaceOrientationMaskPortrait;
} else {
return UIInterfaceOrientationMaskAll;
}
}
But that method doesn't get called...
How should I do this?
Why don't you select the wanted ones here:
Select your app in project navigator -> general -> select your target -> scroll down to deployment info.
If my understanding is right then I have given answer for this query so u could follow this link.
Do let me know if any doubt.
Okay so got solution for your iOS 7 as below method write down in appDelegate class.
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[[[[[UIApplication sharedApplication] keyWindow] rootViewController] childViewControllers] lastObject] isKindOfClass:[ViewController class]]) //Here you could provide your view controller and provide orientation which u want for that particular view controller.
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskLandscape;
}
}
This will help you out for iOS 7.
The problem was solved by implementing the methods on the navigation controller that owns all the views
I am making game which supports only landscape orientation but I am also using a library to share my game video but that share screen require portrait orientation , If I don't enable portrait orientation my game got crash but If I enable portrait orientation to avoid this crash then my whole game become useless by becoming portrait as it is only for landscape.
This is my game Landscape View as shown by figures below,
This is the Library Portrait View to Share video
My Game View after sharing video from library
Please help me How can I enable portrait orientation for this library to avoid crash
and my rest of the app always remain in landscape and it never goes to portrait orientation.
Thanks
Add the following method to your application's AppDelegate.m file:
// IOS 6
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
In both cases you must also make sure that you have added the landscape only orientation handling code to your game's main UIViewController.
// IOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
// IOS 6
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Try to implement orientation methods to your view controller.
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html
I hope this help you.
In the view controller you want to support orientation override supportedInterfaceOrientations method.
I did like this...
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
I have an app that uses the proximity sensor but the proximity sensor does not work in landscape mode. I have heard that if you keep the status bar in portrait mode it the sensor will work
I have tried this but it did not work.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
The status bar still switched into landscape mode.
What do I do?
If you would like to keep your app in portrait mode regardless of DeviceOrientation, I would suggest you add the following code to your viewController.
- (BOOL) shouldAutorotate{
return NO;
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
This will ensure that your app will start in portrait mode, and stay in portrait mode, even if the device is turned.
EDIT: In order to keep the app in landscape while having just one view on portrait mode, add the above code to the one viewController you would like to restrict to portrait mode.
Add the following function to your appDelegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
/* This is in order to allow views that do not support landscape mode to be able to load in
*/
return UIInterfaceOrientationMaskAll;
}
Add the following code to your other view controllers:
- (BOOL) shouldAutorotate{
return YES;
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight; //you can choose either landscape orientation here
}
I suggest you use this hierarchy:
RootViewController - it will contain the reference (preferably
strong) to your proximity sensor, which I recommend you run on a
background thread. This will support only portrait mode, so your
proximity sensor will work ok (I hope).
displayViewController - it will contain all the UI elements you have, and support only landscape mode
You could manage communication between both of them by using delegates
Also, after the viewDidApper of RootViewController, please use the presentViewController (iOS 6.0 and above) or presentModalViewController (iOS 5.x) selector to add the displayViewController's view on screen. Using [self.view addSubview: displayViewController.view]; will not work (I speak from personal experience).
In previous iOS versions, our video would rotate automatically but in iOS 6 this is no longer the case. I know that the presentMoviePlayerViewControllerAnimated was designed to do that before but how can I tell the MPMoviePlayerViewController to rotate automatically?
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
In appdelegate.m :
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[self.window.subviews.lastObject class].description isEqualToString:#"MPMovieView"]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
Kinda a hack, but works well...
I just ran into the same problem. James Chen's solution is correct, but I ended up doing something a little simpler that also works - overriding application:supportedInterfaceOrientationsForWindow in my app delegate and returning allButUpsideDown if my rootView controller was modally presenting an MPMoviePlayerViewController. Admittedly a hack, and may not be appropriate to all situations, but saved me having to change all my view controllers:
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [rootViewController.modalViewController isKindOfClass:MPMoviePlayerViewController.class ] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
This is not limited to MPMoviePlayerViewController. From iOS 6 the autorotation has been changed. see Autorotate in iOS 6 has strange behaviour .
To make your app behave as pre-iOS 6, you have to make the app support all orientations (edit UISupportedInterfaceOrientations in plist), then for all other view controllers which don't support rotation, override this method to return NO:
- (BOOL)shouldAutorotate {
return NO;
}
By default MPMoviePlayerViewController supports all orientations so this should be enough to make it work.