UIViewAutoresizingNone:旋转后调整大小
我有一个带有 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:
After Rotation:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要为此使用根视图,而是将子视图添加到视图控制器的视图中。 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 aUINavigationController
, 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.).