我有两个viewController,所以我希望第一个viewController可以旋转所有侧面,第二个viewController只能旋转左侧。这是我在第二个viewController中的代码。 非常感谢你。
-(NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
答案 0 :(得分:0)
如果您使用的是navigationController, 创建一个这样的类别,
@interface UINavigationController (Rotation_IOS6)
@end
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
if([self.visibleViewController isMemberOfClass:NSClassFromString(@"SecondViewController")])
{
return UIInterfaceOrientationMaskLandscapeLeft
}
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return [[self topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if([self.visibleViewController isMemberOfClass:NSClassFromString(@"SecondViewController")])
{
return UIInterfaceOrientationMaskLandscapeLeft
}
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
答案 1 :(得分:0)
- (BOOL)shouldRotateToOrientation:(UIDeviceOrientation)orientation {
if (orientation == UIDeviceOrientationLandscapeLeft) {
return NO;
}
else if (orientation == UIDeviceOrientationLandscapeRight) {
return NO;
}
else if (orientation == UIDeviceOrientationPortrait) {
return NO;
}
else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
return YES;
}
}
//使用此方法检查要执行的方向,如果是,则可以返回no //想要停止方向,如果你返回是,那么方向执行
答案 2 :(得分:0)
首先,您需要添加NavigationController的类别
声明AppDelegate中的bool用于所有的projcet。
声明属性AppDelegate.h
@property BOOL * islandscape;
AppDelegate.m文件
@synthesize islandscape;
.h文件
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface UINavigationController (orientation1)
@end
.M文件
#import "UINavigationController+orientation1.h"
@implementation UINavigationController (orientation1)
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
if (delegate.islandscape)
{
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
@end
然后在SeconViewController中使用那个bool varible。
delegate.islandscape=Yes;