更改设备旋转时的 iPhone 背景图像
我有一个 UIImageView 作为控件后面的背景,旋转设备时出现问题。我想根据方向
使用不同的图像
。
那么处理这个问题的最佳方法是什么? 添加和删除横向和纵向的每个 UIImageView
? 将两者都放在视图上并隐藏/显示适当的一个? 或者也许有一些类或 UIObject 来处理这个问题?
TIA
I have an UIImageView
as a background behind my controls, the problem comes when rotating the device. I'd like to use a different image
depending on the orientation
.
So what would be the best way to handle that?
Adding and removing each UIImageView
for landscape and portrait?
Having both on the view and hide/show the appropriate one?
Or maybe there is some class or UIObject
for handling that?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用它,将两张背景图像叠加在一起,一张的 alpha = 1.0,另一张的 alpha = 0.0。然后,当您旋转时,使用动画将 alpha 分别过渡到 0.0 和 1.0,以获得淡入淡出效果。如果您选择这种方法,我建议将动画代码放在
-viewWillAppear:
中,例如,如下所示:You can get funky with it and have both background images overlaid, one with alpha = 1.0 and the other with alpha = 0.0. Then, when you rotation, use an animation to transition the alphas to 0.0 and 1.0, respectively to get a fade-in fade-out effect. If you choose this approach, I recommend putting the animation code in
-viewWillAppear:
For example, something like this:您只需将其图像属性设置为不同的图像即可。
You can just set its image property to a different image.
现在您实际上可以使用尺寸类别来达到此目的。您需要做的就是将图像设置为任何宽度紧凑高度并执行本文中给出的提示:http://pinkstone.co.uk/how-to-handle-device-rotation-since-ios-8/
这就是背景图像在旋转时发生变化所需的全部内容。
Now you can actually use size classes for this purpose. All you need to do is to set images for Any width compact height and do the hint given in this article: http://pinkstone.co.uk/how-to-handle-device-rotation-since-ios-8/
That's all you need for your background image to change on rotation.