UIViewAutoresizingNone:旋转后调整大小

发布于 2024-11-03 11:30:18 字数 1741 浏览 2 评论 0原文

我有一个带有 AppDelegate 的简单 IPAD 结构,其中包含来自 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:

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

clockVC 的边界由 IB 定义并在应用程序中覆盖:didFinishLaunching... 宽度和高度分别为200和150。ClockVC

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

/ 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)时,调整大小以占据整个屏幕。

为什么 ??我想保持初始大小。

这是我的问题的屏幕截图。 旋转前: 在此处输入图像描述

旋转后: 在此处输入图像描述

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 has a viewDidLoad defined by this code :

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

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

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;}
     ];
}

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:
enter image description here

After Rotation:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2024-11-10 11:30:18

不要为此使用根视图,而是将子视图添加到视图控制器的视图中。 UIViewControllers 通常被设计为填充其容器的整个空间(在本例中为窗口)。

例如,如果您将 UIViewController 添加到 UINavigationController,导航控制器将接管根据导航控制器的布局调整视图控制器视图大小的责任(无论是导航控制器还是导航控制器)。栏可见等)。我不确定 UIWindow 的行为到底如何(我认为这没有很清楚地记录),但在 SDK 的很多地方,视图控制器的父级负责其子级的定位和大小(UIPopoverController< /code>、UITabBarController 等)。

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).

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.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文