简体   繁体   English

makeKeyAndVisible更改视图iOS 5的方向

[英]makeKeyAndVisible changes orientation of view iOS 5

In method application:didFinishLaunchingWithOptions in AppDelegate I initiate a view controller and add to navigation view controller that becomes window root view controller. 在AppDelegate的方法application:didFinishLaunchingWithOptions中,我启动了一个视图控制器,并将其添加到导航视图控制器中,成为窗口根视图控制器。 Because my iPad app is only horizontal orientation all my view controllers are made for landscape. 因为我的iPad应用程序只是水平方向,所以我所有的视图控制器都是为横向而设计的。

Here is the code: 这是代码:

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

return YES;

When I put breakpoint on "self.window.rootViewController = self.myNavigationController;" 当我在“ self.window.rootViewController = self.myNavigationController;”上设置断点时 line and call in console to display view details, I get following: $0 = 0x0c89d010 > 行并在控制台中调用以显示视图详细信息,我得到以下信息:$ 0 = 0x0c89d010>

which I read the rect is orientation mode (1024 width and 748 height) 我读到的rect是定向模式(1024宽度和748高度)

The next breakpoint that is on "return YES;" 下一个断点位于“返回YES”。 shows me this: $1 = 0x0c89d010 > 告诉我:$ 1 = 0x0c89d010>

which copy an object (as far as I can see) and changes orientation (768 width and 1004 height) 复制对象(据我所知)并 更改方向(768宽度和1004高度)

This only happens in iOS5, however iOS6 works as expected 这仅在iOS5中发生,但是iOS6可以正常工作

Is there any known issue with MakeKeyAndVisible method that I should know? 我应该知道的MakeKeyAndVisible方法是否存在任何已知问题? Or may be it is lack of my understanding how makeKeyAndVisible works 或者可能是因为我不了解makeKeyAndVisible如何工作

Try creating a custom UINavigationController with all the orientation methods inside it and use it in your app. 尝试创建一个自定义UINavigationController并在其中包含所有方向方法,然后在您的应用中使用它。

It would be something like this 就像这样

CustomNavigationController.h CustomNavigationController.h

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

CustomNavigationController.m 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

This way your orientations would be working accordingly in your corresponding viewCotrollers. 这样,您的方向将在相应的viewCotrollers中相应地工作。

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

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