我正在使用故事板开发 iPad 横向应用程序。我已经完成了以下步骤。我的应用程序是在模拟器上的横向模式中打开屏幕.. 但得到错误的框架。
在 view controller.m 中实现以下方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
Run Code Online (Sandbox Code Playgroud)现在,当我获取框架和边界的 NSLog 时,它会显示我的肖像框架。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"bounds ::%@",NSStringFromCGRect(self.view.bounds));
NSLog(@"frame ::%@",NSStringFromCGRect(self.view.frame));
}
Run Code Online (Sandbox Code Playgroud)
结果日志:
bounds ::{{0, 0}, {748, 1024}}
frame ::{{20, 0}, {748, 1024}}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
在 viewDidLoad 方法中,您没有得到正确的边界。您可以在 viewDidAppear 方法中执行此操作。viewDidAppear 方法在视图完全加载并具有正确边界时调用。
| 归档时间: |
|
| 查看次数: |
1502 次 |
| 最近记录: |