iPhone的自动取向
我使用 UIDeviceOrientationDidChangeNotification
来获取横向和肖像模式的通知。在我的项目中,我需要相应地更改放置在 UIView
上的 UIControls
的位置。我是否必须手动更改每个 UIControl
的帧大小,因为这很忙?
I have used UIDeviceOrientationDidChangeNotification
to get notified of landscape and potrait mode. In my project I'm required to change the positions of UIControls
placed on the UIView
accordingly. Do I have to change the frame size manually for each UIControl
, as this is hectic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的视图控制器中,您应该实现方法:
对于支持的方向,此方法应该返回
YES
。如果您希望子视图自动调整大小和位置,那么您应该为该视图设置适当的属性
autoresizingMask
。例如:In your view controller you should implement method:
This method should return
YES
for supported orientations.If you want your subviews to resize and reposition automatically then you should set appropriate property
autoresizingMask
of that views. For example:您确实需要使用 shouldAutorotateToInterfaceOrientation... 方法,但在它正常工作之前您需要做更多的事情。首先,您需要两个 xib 文件,一个用于横向,一个用于纵向。然后,您需要像这样使用您的函数:
至于准备横向或纵向视图,使用自动调整大小可以工作,但您可能需要完全独立的 xib。我找不到更改活动视图控制器内的 xib 的方法,因此我建议创建一个单独的视图控制器实例。示例:
当您展示 viewController 的第一个实例时,将其与肖像 xib 一起展示。您可能还需要一个布尔值来跟踪当前的 xib。然后实现此代码:
编辑:
我还发现有人在我的一个问题上发布了这一点。与使用我上面的方法相比,它可能会帮助您的应用程序更有效地工作:
http://aseriesoftubes.com/articles/ipad-development-101-orientation/
You do need to use the shouldAutorotateToInterfaceOrientation... method but you need to do a little more before it will work properly. First of all, you will need two xib files, one for a landscape orientation and one for a portrait orientation. You will then need to use your function like this:
As for preparing for landscape or portrait views, using autoresizing can work but you may need to have totally seperate xibs. I could not find a way to change the xib within the active view controller, so I would suggest making a seperate instance of your view controller. Example:
When you present your first instance of the viewController, present it with the portrait xib. You may also need a boolean to keep track of the current xib. Then have this code implemented:
EDIT:
I also found this which someone posted on one of my questions. It may help your app work more efficiently than using my method above:
http://aseriesoftubes.com/articles/ipad-development-101-orientation/