【问题标题】:issues on Orientation iOS关于 iOS 定位的问题
【发布时间】:2012-09-10 19:20:40
【问题描述】:

我正在开发一个仅支持纵向的应用程序,正如我的 Info.plist 文件中所写的那样。 但是当我旋转设备时,状态栏会旋转,但视图不会。 我不使用 InterfaceBuilder 来设置我的视图和初始窗口,我以编程方式编写:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

   self.window.rootViewController = myRootViewController;

   [self.window makeKeyAndVisible];
   return YES;
}

在我所有的观点中都有方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

我该如何解决这个问题?

【问题讨论】:

    标签: ios uiinterfaceorientation uiwindow uideviceorientation


    【解决方案1】:

    我通过在 Info.plist 文件的“支持的界面方向”字段中设置“纵向(底部主页按钮)”来做到这一点。

    另一种方法是从所有视图控制器中删除 shouldAutorotateToInterfaceOrientation: 的默认实现。

    【讨论】:

    • 是的,如果您删除 shouldAutorotateToInterfaceOrientation:,您的视图将不再尝试旋转。
    • 一些其他的东西在这里阻碍,我试过了,它对我有用
    【解决方案2】:

    尝试添加这个:

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
    

    给你的:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    在 AppDelegate 中。

    希望这会有所帮助!

    【讨论】:

    • 没有。不能解决我的问题。状态栏仍在旋转,当 UINavigationController 推送 UIViewController(设备处于横向模式)时,UINavigationBar 会调整高度,但视图始终是纵向的
    猜你喜欢
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    相关资源
    最近更新 更多