Reputation: 5232
I am getting an issue regarding to iphone screen orientation. My application's base sdk is ios 6.0, deployment target is 4.3 and running on ios 5.0 and 5.1
In application's plist file I set Portrait (bottom home button)
, Landscape (left home button)
and Landscape (right home button)
. I am developing an Universal app. So in every view's - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
method I am conditionally returning portrait
for iphone and both landscape
for ipad.
My navigation flow is :
An UINavigatinController
pushing UITableViewControler
first tab have UINavigationController
pusing 2 views one by one on the rootViewController
.
In my last viewController's - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
method I returned YES
. But the app this view is not being rotate at all. Not even calling - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
method. :(
My requirement is to support both landscape and portrait orientation to only one viewController not to whole app.
Please help me.
Upvotes: 1
Views: 436
Reputation: 8501
You should implement all these methods to make it work for all the devices having ios >= 4.3 version..
// Autorotation (iOS <= 5.x)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight||interfaceOrientation == UIInterfaceOrientationPortrait) ;
}
// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Upvotes: 0
Reputation: 2745
You can solve this Orientation Issue by this code in View Controller Class.
#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
#endif
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight); //IOS_5
}
#endif
You have to define this code in .pch file.
Code :
#define IOS_OLDER_THAN_6 ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0)
#define IOS_NEWER_OR_EQUAL_TO_6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
Hopefully, It works.
Thanks.
Upvotes: 1
Reputation: 869
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
// setFrames=CGRectMake(x, y, w, h);
}
Upvotes: 0
Reputation: 2595
How many UIViewController do you have? Maybe a 2, 3 or more.
Try at each viewcontroller add a code
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
NSLog(@"viewcontroller: %@", self);
return YES;
}
and you will know, which view controller takes a rotate notification. It seems problem im Modal view controller.
Upvotes: 0
Reputation: 82
For iOS 6, use supportedInterfaceOrientations
& shouldAutorotate
instead of shouldAutorotateToInterfaceOrientation:
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape; (Check for device type here and return appropriate orientations)
}
- (BOOL) shouldAutorotate {
return YES;
}
Upvotes: 0