方法一.强制手机旋转(自带有旋转动画)
1.appdelegate 代码如下
#import <UIKit/UIKit.h>
@interfaceAppDelegate :UIResponder <UIApplicationDelegate>
@property(nonatomic,assign)BOOLshouldRote;
@property (strong, nonatomic) UIWindow *window;
@end
#import"AppDelegate.h"
@interfaceAppDelegate()
@end
@implementationAppDelegate
//屏幕旋转全屏
-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window{
UIDevice*device = [UIDevicecurrentDevice];
if(!_shouldRote|| device.orientation==UIDeviceOrientationPortraitUpsideDown)returnUIInterfaceOrientationMaskPortrait;
returnUIInterfaceOrientationMaskLandscapeRight;
}
@end
2.跳转横屏控制器代码
AppDelegate*delegate = (AppDelegate*)[UIApplicationsharedApplication].delegate;
delegate.shouldRote=YES;
[[UIDevicecurrentDevice]setValue:[NSNumbernumberWithInt:UIDeviceOrientationLandscapeRight] forKey:@"orientation”];
[self.navigationController pushViewController:[NextVC new] animated:YES];
方法二.正常push/present(无旋转动画)
1.在横屏控制器添加横屏contentview,在contentview里面添加ui控件
- (void)viewDidLoad {
[superviewDidLoad];
self.contenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.height, self.view.width)];
[self.view addSubview:self.contenView];
[self.view addSubview:subviews];
}
2.旋转contentview
- (void)viewDidLayoutSubviews{
[superviewDidLayoutSubviews];
//由于旋转后的origin偏差,修正contenView的origin
// [UIView animateWithDuration:0.3 animations:^{
self.contenView.transform=CGAffineTransformRotate(CGAffineTransformIdentity,M_PI_2);
self.contenView.frame=self.view.bounds;
// }];
}