iPhone SDK:方向(横向和纵向视图) [英] iPhone SDK: Orientation (Landscape and Portrait views)

查看:115
本文介绍了iPhone SDK:方向(横向和纵向视图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有我的正常的应用程序是在肖像模式。我可以强制我的应用程序去景观模式的视图(使用navigationcontroller和viewcontroller),如下:

Okay, I've got my normal app which is in portrait mode. I can force my app to go to landscape mode for a view (using navigationcontroller and viewcontroller) like this:

- (void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}

但是当我回到主菜单回到肖像。我尝试这个代码:

But then when I go back to the main menu (tableview) it goes straight back to portrait. I try this code:

- (void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}

但这不行。

任何想法?

推荐答案

看看函数 shouldAutorotateToInterfaceOrientation: 在UIViewController类中。如果UIView支持方向,此函数返回YES。如果你只返回YES到横向,那么iPhone将自动以这个方向。

Take a look at the function shouldAutorotateToInterfaceOrientation: in the UIViewController class. This function returns YES if the orientations is supported by your UIView. If you return YES only to the landscape orientation, then the iPhone will automatically be put in that orientation.

下面的代码应该这样做。将它放在控制要以横向模式放置的视图的UIViewController中。

The following code should do it. Put it in the UIViewController that controls the view that you want to put in landscape mode.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}

这篇关于iPhone SDK:方向(横向和纵向视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆