UIViewAutoresizingNone:旋转后调整大小 [英] UIViewAutoresizingNone: Resize after rotation

查看:155
本文介绍了UIViewAutoresizingNone:旋转后调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的IPAD结构,带有一个AppDelegate,其中包含来自viewController的视图:

i have a simple structure for IPAD with an AppDelegate that include a view from a viewController :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    ClockVC *clockVC = [[ClockVC alloc]init];
    clockVC.view.frame = CGRectMake(100, 100, clockVC.view.bounds.size.width, clockVC.view.bounds.size.height);

    [self.window addSubview:clockVC.view];
    [self.window makeKeyAndVisible];

    return YES;
}

clockVC具有由此代码定义的viewDidLoad:

clockVC has a viewDidLoad defined by this code :

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.autoresizingMask = UIViewAutoresizingNone;
    self.view.autoresizesSubviews = UIViewAutoresizingNone;
}

clockVC的边界由IB定义,并在application:didFinishLaunching ...中覆盖. 宽度和高度分别为200和150.

Bounds of clockVC are defined by IB and override in application:didFinishLaunching... Width and Height are respectively 200 and 150.

ClockVC实现了一步自动旋转的方法: /

ClockVC implements method for one-step auto-rotation : /

/ Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
     [UIView animateWithDuration:0.5 
                     animations:^{self.view.alpha = 0;}
     ];
}

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [UIView animateWithDuration:1 
                     animations:^{self.view.alpha = 1;}
     ];
}

在第一次加载时,将正确查看页面,并且ClockVC视图处于适当位置. 当我旋转clockVC视图(将autoResizeMask设置为UIViewAutoresizingNon)调整大小以占据整个屏幕时.

At the first load the page is correctly viewed and clockVC view is in position. When i rotate clockVC view (whose autoResizeMask is set to UIViewAutoresizingNon)resize to take the entire screen.

为什么?我想保持最初的大小.

Why ?? i'd like to mantain initial size.

以下是我的问题的屏幕截图. 轮换之前:

Here screenshots of my problem. Before rotation:

旋转后:

推荐答案

请勿为此使用根视图,而应在视图控制器的视图中添加一个子视图. UIViewControllers通常旨在填充其容器的整个空间(在这种情况下为窗口).

Don't use the root view for this, add a subview to the view controller's view instead. UIViewControllers are typically designed to fill the entire space of their container (the window in this case).

例如,如果要将UIViewController添加到UINavigationController,则导航控制器将根据导航控制器的布局(无论导航栏是否可见等)来接管调整视图控制器视图大小的责任.我不确定UIWindow的行为如何(我认为这没有很清楚地记录下来),但是在SDK的很多地方,视图控制器的父级负责其子级的位置和大小(UIPopoverControllerUITabBarController等.)

For example, if you would add a UIViewController to a UINavigationController, the navigation controller takes over the responsibility to size the view controller's view according to the navigation controller's layout (whether the navigation bar is visible etc.). I'm not sure how exactly UIWindow behaves (I think this is not very clearly documented), but in a lot of places in the SDK, a view controller's parent is responsible for the positioning and size of its children (UIPopoverController, UITabBarController et.al.).

这篇关于UIViewAutoresizingNone:旋转后调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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