.h files:
#import <UIKit/UIKit.h>
@interface LSLRotationManager : NSObject
@property (nonatomic, readonly) UIInterfaceOrientationMask interfaceOrientationMask; @property (nonatomic) UIDeviceOrientation orientation;
+ (instancetype)defaultManager;
@end
.m files
#import “LSLRotationManager.h”
#import <objc/message.h>
static LSLRotationManager *INSTANCE = nil;
@interface LSLRotationManager ()
@property (nonatomic, readwrite) UIInterfaceOrientationMask interfaceOrientationMask;
@end
@implementation LSLRotationManager
#pragma mark – singleton
+ (instancetype)defaultManager {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
INSTANCE = [[super allocWithZone:nil] init];
INSTANCE.interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;
});
return INSTANCE;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
return [self defaultManager];
}
#pragma mark – setter methods
– (void)setOrientation:(UIDeviceOrientation)orientation {
if (_orientation == orientation) return;
if ([UIDevice currentDevice].orientation == orientation) {
// Force the rotation to be different than before
[[UIDevice currentDevice] setValue:@(_orientation) forKey:@”orientation”];
}
_orientation = orientation;
UIInterfaceOrientationMask interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;
switch (orientation) {
case UIDeviceOrientationPortrait:
interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;
break;
case UIDeviceOrientationPortraitUpsideDown:
interfaceOrientationMask = UIInterfaceOrientationMaskPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeRight:
interfaceOrientationMask = UIInterfaceOrientationMaskLandscapeLeft;
break;
case UIDeviceOrientationLandscapeLeft:
interfaceOrientationMask = UIInterfaceOrientationMaskLandscapeRight;
break;
default:
interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;
break;
}
[LSLRotationManager defaultManager].interfaceOrientationMask = interfaceOrientationMask;
// Force rotation to full screen
[[UIDevice currentDevice] setValue:@(orientation) forKey:@”orientation”];
}
Call it when called
[LSLRotationManager defaultManager].orientation = UIDeviceOrientationLandscapeLeft
With respect to ok