Make UIView Landscape Orientation in UIViewController? - iphone

I have added a UIView as subview of my UIViewController, when I am trying change the orientation, it is not working, Please let me know how should i change the Interface orientation of my UIView?
Regards
Sri

try this..
[[UIDevice currentDevice] performSelector:#selector(setOrientation:) withObject:(id)UIInterfaceOrientationLandscapeRight];

Make sure you return YES for -shouldAutorotateToInterfaceOrientation: in your view controller.

Note that setOrientation is a private API according to the documentation of UIDevice (that property is read only). If you use it, your application will be rejected during the App Store review.
Instead forcing an orientation, you should override shouldAutorotateToInterfaceOrientation in all the view controllers of the hierarchy of that view and return YES only for the orientations you want to support.

Related

How to allow a particular view controller to support for both landscape and portrait orientation

My application is navigation based application which is supporting iOS 6. Except a view controller all others will support only portrait mode. Particular view controller alone has to support both landscape and portrait orientations.
I searched lot there are tons of questions for this but none of the answer is suitable for me. If some one knows, kindly guide me
I set the orientation as Portait in Project -> Targets -> Summary -> Supported orientation
First you should use methods for the iOS6 presented in UIViewController documentation if you are making your app for iOS6. Orientation method like shouldAutorotateToInterfaceOrientation is deprecated in iOS6, alternate method for iOS6 is shouldAutoRotate. You should only use the old method if your app is supporting also iOS5.
Second If you are using UINavigationcontroller in your application and you need to have different interface orientations then navigationController could mess up the interface orientation in the application. Possible solution (worked for me) is to implement a custom UINavigationController and override the interface orientation methods within that custom UINavigationController class, this will make your viewControllers rotate according to the orientation you set because your controllers are pushed from the UINavigationController. Don't forget to add those methods in your particular viewController also.
CustomNavigationController.h
#interface CustomNavigationController : UINavigationController
#end
CustomNavigationController.m
#implementation CustomNavigationController
//overriding shouldRotate method for working in navController
-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
I really think that the correct way to do it is to set both landscape and portrait as supported orientations, and not allowing a change in the orientation on the VC you don't want to rotate, by returning NO on the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
if the orientation that was passed to the method was not supposed to be supported.
As mentioned in the comments, this method can no longer be used. You should use :
-(BOOL) shouldAutorotate
And find out the current orientation inside this function and returning NO if you don't want to rotate.
Don't forget to allow your application different Orientations!
otherwise nothing from above will work
Set it in project target on General under Deployment Info section:

Autorotation in iOS6

I am updating my app for iOS 6 and having issues with the changes to autorotation. My app has a bunch of view controllers and all of them should only support the portrait layout except 1 which should support all 3 orientations except upside down.
If I add the application:supportedInterfaceOrientationsForWindow: method to the app delegate do I have to add conditions there to check if im displaying the one VC I want to be able to rotate?
The documentation states that if I implement supportedInterfaceOrientations on a VC it should override the app delegate method but this doesn't appear to be the case. I have an log statement in the method on the child VC and it is called once when the VC loads but its not called when I rotate the device, but the method in the app delegate is.
If I completely remove the method from the app delegate the orientation of my VC's seems to be completely dependent on my apps supported interface orientation settings. This of course seems to be due to the method supportedInterfaceOrientations being called once on creation of the VC but never when the device is rotated.
Does anyone have any ideas or suggestions? It would be much appreciated.
Replace
[window addSubview:viewController.view];
with
window.rootViewController = viewController;
You also need to override - (BOOL) shouldAutorotate and return "YES". This makes it so you declare what orientations your VC supports with "supportedInterfaceOrientations" and then on rotation it should call "shouldAutorotate". If you have any navigation controller or tabbar you may need to subclass those to do the same thing within them. I had this issue recently myself.
try this...
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
// here to implement landscope code
}
else
{
// here to implement setframePortrait
}
}

How to respond to interface orientation changes?

I know the app delegate can say "yo man, I want thais new landscape orientation!" or "no thanks, don't want landscape!" and then the device won't do it.
How to implement this?
The active view controller's shouldAutorotateToInterfaceOrientation: method determines whether the interface will rotate.
For launch, there is a key in your Info.plist file that needs to be set if you want to be able to launch in orientations other than portrait.
I prefer to get the orientation notification by registering UIDeviceDidChangeOrientationNotification. The delegate of UIViewController about orientation always confuses me. I prefer to control the animation effect by myself.

How to detect orientation in costomNavigationbar?

i need to draw PortraitImage or LandscapeImage when my costomNavigation has been change to portrait or landscape.
You need to override willRotateToInterfaceOrientation:duration: in your UIViewController. This will give you a call every time the app changes its orientation.
You can detect orientation by using the UIDevice Class, as shown here:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/orientation
You need to use the methods
- (void)beginGeneratingDeviceOrientationNotifications
and
- (void)endGeneratingDeviceOrientationNotifications
That should probably work.

Managing subview when orientation change on iPhone OS 3.0

I am experiencing difficulties managing my view controller rotation.
Here is my app structure :
[Window]
---[addSubview:MainViewController.view]
My MainViewController's view contains an UIImageView which I need to rotate, this is my app background.
In my AppDelegate and MainController I overrided shouldAutorotateToInterfaceOrientation to return YES, but when I rotate my device nothing change. Even the status bar.
Should I manually apply transformation to my views when I receive UIDeviceOrientationDidChangeNotification ?
In IB I set resize subviews to YES in mainViewController.view.
So I am a little bit lost...
Thanks for your help.
thierry
Actually, you should override shouldAutorotateToInterfaceOrientation: — notice the colon, it's significant in ObjC — and only in the current view controller.
#implementation MainViewController
...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}