仅在横屏模式下设置一个视图控制器

4

我是ios的新手。

我希望在横向模式下仅显示一个viewController,其他所有模式均为纵向。

请帮助我并告诉我如何在应用程序中仅更改一个视图以适用于横向模式。

我已经搜索过了,但没有找到特定的答案。


感谢Rotim的纠正...... - Bilal hussain
3个回答

4

如果您正在使用导航控制器,并且将此“横向定向”视图控制器推入的控制器仅处于纵向模式,则必须通过CGAffineTransformation手动旋转UI视图。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // If you require full screen then hide the navigation bar with following commented line.
    //[self.navigationController setNavigationBarHidden:YES animated:NO];

    // Rotates the view.

    CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI/2);
    self.view.transform = transform;

    // Repositions and resizes the view.
    // If you need NavigationBar on top then set height appropriately 
    CGRect contentRect = CGRectMake(0, 0, 480, 320);
    self.view.bounds = contentRect;
}

谢谢兄弟,它太棒了!我花了很多时间,你的答案非常好。对我来说运行得很好。 - Surya

2
对于iOS6,将此方法添加到您的ViewController中。
-(NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskLandscape;
}

0
你正在使用UINavigationController吗?
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL) shouldAutorotate {
    return YES;
}

谢谢Markm!是的,我正在使用navigationcontroller。 - Bilal hussain

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接