繁体   English   中英

makeKeyAndVisible更改视图iOS 5的方向

[英]makeKeyAndVisible changes orientation of view iOS 5

在AppDelegate的方法application:didFinishLaunchingWithOptions中,我启动了一个视图控制器,并将其添加到导航视图控制器中,成为窗口根视图控制器。 因为我的iPad应用程序只是水平方向,所以我所有的视图控制器都是为横向而设计的。

这是代码:

self.myViewController = [[MyViewController alloc] init];
self.myNavigationController = [[MyNavigationController alloc] initWithRootViewController: self.myViewController];
self.window.rootViewController = self.myNavigationController;
[self.window makeKeyAndVisible];

return YES;

当我在“ self.window.rootViewController = self.myNavigationController;”上设置断点时 行并在控制台中调用以显示视图详细信息,我得到以下信息:$ 0 = 0x0c89d010>

我读到的rect是定向模式(1024宽度和748高度)

下一个断点位于“返回YES”。 告诉我:$ 1 = 0x0c89d010>

复制对象(据我所知)并 更改方向(768宽度和1004高度)

这仅在iOS5中发生,但是iOS6可以正常工作

我应该知道的MakeKeyAndVisible方法是否存在任何已知问题? 或者可能是因为我不了解makeKeyAndVisible如何工作

尝试创建一个自定义UINavigationController并在其中包含所有方向方法,然后在您的应用中使用它。

就像这样

CustomNavigationController.h

#import <UIKit/UIKit.h>
@interface CustomNavigationController : UINavigationController
@end

CustomNavigationController.m

#import "CustomNavigationController.h"


@interface CustomNavigationController ()

@end

@implementation CustomNavigationController


//overriding shouldAutorotateToInterfaceOrientation method for working in navController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return   [self.topViewController shouldAutorotateToInterfaceOrientation];

}

//other methods

这样,您的方向将在相应的viewCotrollers中相应地工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM