实现UITabbarcontroller 的类方法, 可以用里面的nag push到另一个view时,旋转
不需要再在各个viewcontroll中 另外实现此方法
@implementation UITabBarController(Rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
return [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
else {
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
}
@end
实现tabbarcontroll中 某一个viewcontroll (MVLCMovieListViewController)单独旋转
不需要再在各个viewcontroll中 另外实现此方法
@implementation UITabBarController(Rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
for (UIViewController *viewcontroller in [(UINavigationController*)self.selectedViewController viewControllers])
{
if ([viewcontroller isKindOfClass:[MVLCMovieListViewController class]]) {
return [viewcontroller shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
}
else
return [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
} else {
// return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
// return [self.selectedViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
}
// return NO;
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
@end
//2013.08.21新增 导航中 禁止某个viewController旋转 可能会造成view的位置改变
先添加这个类别
@implementation UINavigationController (Rotation)
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
@end
再在.m文件中添加如下代码
//禁止旋转屏幕
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
参考 http://blog.csdn.net/yiyaaixuexi/article/details/8035014
////ios6中 禁止某个view旋转 不会造成位置偏移
-(NSUInteger)supportedInterfaceOrientations{
if([[self topViewController] isKindOfClass:[self.superclass class]])
return UIInterfaceOrientationMaskAllButUpsideDown;
else
return UIInterfaceOrientationMaskPortrait;
}