iOS 7 Interface Orientation

iOS 7 Interface Orientation

In my app for iPhone its only support the portrait view only, but as per requirement need to support landscape view only for on view, at that time I use following way and its help me :

In your app delegate .h

@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

BOOL flagOrientationAll;
}

@property (assign) BOOL flagOrientationAll;

Add following method in your app delegate .m file

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
//NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
if([UICommonUtils isiPad]){
return UIInterfaceOrientationMaskAll;
}else if(flagOrientationAll == YES){
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}

Implement following way in your view which you want to rotate in both portrait and landscape both for iPhone device

-(void)viewWillAppear:(BOOL)animated
{
self.tabBarController.delegate = self;

PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = YES;
}
}

-(void)viewWillDisappear:(BOOL)animated
{
//NSLog(@"viewWillDisappear -- Start");
PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = NO;
}

see this post also: How to set one of the screens in landscape mode in iphone?

Handling Interface Orientation with Animation in iOS7

Since there was no answer, I was forced to dig through old documentations and spend a few days trying out various solutions. Long story short: the below method do the job just done (I hope it will help people who want to support legacy devices):

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// Typecast the interface orientation to which the app is transitioning
UIDeviceOrientation orientation = (UIDeviceOrientation)toInterfaceOrientation;

// Call method that handles the resizing
[self handleInterfaceOrientation:orientation withDuration:duration];
} // <- For leagcy iOS7 support

- (void)handleInterfaceOrientation:(UIDeviceOrientation)toInterfaceOrientation withDuration:(NSTimeInterval)duration {

// Calculate screen size the app is transitioning to (ignore iOS8-only devices, such as iPhone 6 and newer)
if ( (toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) ) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if ([[UIScreen mainScreen] bounds].size.height > 480.0f) {
windowSize = CGSizeMake(320.0f, 568.0f);
} else {
windowSize = CGSizeMake(320.0f, 480.0f);
}
} else {
windowSize = CGSizeMake(768.0f, 1024.0f);
}
} else {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if ([[UIScreen mainScreen] bounds].size.height > 480.0f) {
windowSize = CGSizeMake(568.0f, 320.0f);
} else {
windowSize = CGSizeMake(480.0f, 320.0f);
}
} else {
windowSize = CGSizeMake(1024.0f, 768.0f);
}
}

// Animate UI elements to new dimension
[UIView animateWithDuration:duration
delay:0.0f
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
[self populateGalleryScrollView];
} completion:^(BOOL finished) {
// Once rotation is done, disable the rotation view
rotationView.alpha = 0.0f;
}];
} // <- For legacy iOS7 support

iOS 7: How to allow only portrait orientation for VC

If you want different orientation for view controllers, In AppDelegate add this method -

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}

return orientations;
}

and in your ViewController -

-(BOOL)shouldAutorotate{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations{
return (UIInterfaceOrientationMaskAll);//Change this according to your need
}

Hope this will help.

iOS 7 interface orientation 2

I have fixed this issue by re-organizing the layout of the HomeViewController upon orientation change.

Restrict Interface Orientation in iOS 7 and iOS 8

Simple but it work very fine. IOS 7.1 and 8

AppDelegate.h

@property () BOOL restrictRotation;

AppDelegate.m

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if(self.restrictRotation)

return UIInterfaceOrientationMaskPortrait;
else

return UIInterfaceOrientationMaskAll;

}

ViewController

At top: To Detect Device Type

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#define IS_IPHONE_5_IOS7 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
#define IS_IPHONE_6_IOS7 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0f)
#define IS_IPHONE_6P_IOS7 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0f)
#define IS_IPHONE_4_AND_OLDER_IOS7 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height < 568.0f)

#define IS_IPHONE_5_IOS8 (IS_IPHONE && ([[UIScreen mainScreen] nativeBounds].size.height/[[UIScreen mainScreen] nativeScale]) == 568.0f)
#define IS_IPHONE_6_IOS8 (IS_IPHONE && ([[UIScreen mainScreen] nativeBounds].size.height/[[UIScreen mainScreen] nativeScale]) == 667.0f)
#define IS_IPHONE_6P_IOS8 (IS_IPHONE && ([[UIScreen mainScreen] nativeBounds].size.height/[[UIScreen mainScreen] nativeScale]) == 736.0f)
#define IS_IPHONE_4_AND_OLDER_IOS8 (IS_IPHONE && ([[UIScreen mainScreen] nativeBounds].size.height/[[UIScreen mainScreen] nativeScale]) < 568.0f)

#define IS_IPHONE_5 ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_IPHONE_5_IOS8 : IS_IPHONE_5_IOS7 )
#define IS_IPHONE_6 ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_IPHONE_6_IOS8 : IS_IPHONE_6_IOS7 )
#define IS_IPHONE_6P ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_IPHONE_6P_IOS8 : IS_IPHONE_6P_IOS7 )
#define IS_IPHONE_4_AND_OLDER ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_IPHONE_4_AND_OLDER_IOS8 : IS_IPHONE_4_AND_OLDER_IOS7 )

Then Add Function Below:

-(void) restrictRotation:(BOOL) restriction{

AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;}

viewDidLoad

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){

if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)])
{
if(IS_IPHONE_6P){

printf("Device Type : iPhone 6+ ");
[self restrictRotation:NO];
}
else{

printf("Device Type : iPhone 6 ");
[self restrictRotation:YES];
}
}
}
else{

printf("Device Type : iPad");
[self restrictRotation:NO];
}

iOS 3.2 to iOS 7 interface orientation inconsistency

Well at last, I eventually found it!!!

The problem was (I still don't know exactly why) caused by the way I was switching between ViewControllers (the old iOS 3 way).

So to correct if, I test if the method presentViewController:animated:completion is available (God bless respondsToSelector:) and I use it when I can.

Problem solved!



Related Topics



Leave a reply



Submit