我的自我观点有错误的尺寸

Jon*_*han 8 autosize uiview autorotate ios

我的观点有错误的维度.我正在运行景观,但视图报告纵向尺寸"查看宽度= 768.000000高度= 1024.000000"任何想法如何解决?我玩过我试过的自转器

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

它在视图上看起来很好,但尺寸确实与我的应用程序混乱.

nop*_*ole 13

你永远不应该用它frame来告诉你自己的维度. frame相对于父容器视图.要查找与视图自身坐标系相关的尺寸,请使用bounds:self.view.bounds

例如,父视图可以看到子视图具有width = 768和height = 1024,但具有旋转90度变换.这是父视图查看子视图的方式,这就是self.view.frame它的内容.宽度= 1024和高度= 768的子视图反映在视图如何在自己的坐标系中看到自己,即self.view.bounds

  • 你可以正确看到它的最早时间是`viewWillLayoutSubviews`,`viewDidLayoutSubviews`,`viewDidAppear`.供参考:http://stackoverflow.com/questions/12118920/on-an-ios-single-view-app-when-is-the-earliest-time-that-self-view-bounds-is-se (4认同)