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
Various Itms Errors When Trying to Submit Archive to App Store
Sending a Private Message to Your Friends via Facebook iOS Sdk
Ld: Library Not Found for -Lbolts Using Cocoapods
How to Remove Border of the Navigationbar in Swift
Email & Phone Validation in Swift
What Advantage(S) Does Dispatch_Sync Have Over @Synchronized
How to Generate a Barcode from a String in Swift
App Store Connect Message: Your Account Will Soon Need to Be Migrated to Federated Auth
How to Know Users Click Fast Forward and Fast Rewind Buttons on the Playback Controls in Iphone
How to Set Mime Type of Application/Vnd.Apple.Pkpass in Order to Share Pass by Link or Email
Swiftui: Deleting Last Row in Foreach
How Programmatically Restart an iPhone App in iOS
Uislider That Snaps to a Fixed Number of Steps (Like Text Size in the iOS 7 Settings App)
Locking a Uisearchbar to the Top of a Uitableview Like Game Center
How to Remove the Authorization Prompt from Command-Line Instances of Instruments (Xcode)
How to Display the Standard Checkmark on a Uicollectionviewcell