如果用户在查看 MasterViewController 时旋转,则 DetailViewController 的主从应用程序自动旋转不会对齐
我有一个简单的主从应用程序,带有 MasterViewController 和 DetailViewController。在 DetailViewController 内部,我实现了以下代码,以便在旋转视图时我的两个按钮能够正确定位。
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{ firstButton.frame = CGRectMake(20, 240, 50, 50);
secondButton.frame = CGRectMake(390, 240, 50, 50);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
firstButton.frame = CGRectMake(20, 240, 50, 50);
secondButton.frame = CGRectMake(390, 240, 50, 50);
}
else
{
firstButton.frame = CGRectMake(80, 390, 50, 50);
secondButton.frame = CGRectMake(190, 390, 50, 50);
}
}
如果 iPhone 直到 DetailViewController 出现在视图中才旋转,则按钮的位置正确。但是,如果用户在查看 MasterViewController 表格视图时旋转 iPhone,然后点击某个项目,则当 DetailViewController 打开时,按钮的位置不正确。
那么我如何或在哪里放置 MasterViewController 中的按钮呢?谢谢您的帮助!
I have a simple Master-Detail application with a MasterViewController and a DetailViewController. Inside of the DetailViewController I have implemented the following code so that when the view is rotated my two buttons are positioned properly.
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{ firstButton.frame = CGRectMake(20, 240, 50, 50);
secondButton.frame = CGRectMake(390, 240, 50, 50);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
firstButton.frame = CGRectMake(20, 240, 50, 50);
secondButton.frame = CGRectMake(390, 240, 50, 50);
}
else
{
firstButton.frame = CGRectMake(80, 390, 50, 50);
secondButton.frame = CGRectMake(190, 390, 50, 50);
}
}
If the iPhone isn't rotated until the DetailViewController is in view, then the buttons are positioned properly. But if the user rotates the iPhone while viewing the MasterViewController table view and then taps an item, when the DetailViewController opens, the buttons are not positioned correctly.
So how can I or where do I position the buttons from the MasterViewController? Thank you for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 viewDidLoad 或 viewWillAppear 中检查
UIViewController
的interfaceOrientation
属性,例如:You can check
interfaceOrientation
property ofUIViewController
in your viewDidLoad or viewWillAppear for example: