//這段代碼是強(qiáng)制產(chǎn)生橫屏效果亏狰,通過kvo實現(xiàn)
//強(qiáng)制右橫屏? 可以過審核
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}
如果需要實現(xiàn)某些頁面豎屏柳譬,特定頁面橫屏敬扛,可以使用模態(tài)推出頁面方法躁锡,
首先
- (BOOL) shouldAutorotate
{
return NO;
}
然后添加這段代碼
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)deviceOrientationDidChange
{
if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
[self orientationChange:NO];
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
[self orientationChange:YES];
}
- (void)orientationChange:(BOOL)landscapeRight
{
if (landscapeRight) {
[UIView animateWithDuration:0.4f animations:^{
self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
self.view.bounds = CGRectMake(0, 0, Screen_Width, Screen_Height);
}];
} else {
[UIView animateWithDuration:0.4f animations:^{
self.view.transform = CGAffineTransformMakeRotation(0);
self.view.bounds = CGRectMake(0, 0, Screen_Width, Screen_Height);
}];
}