[英]When in the view reload resources when orientation changes?
I have view that have many subviews, and each have it's own graphics, different for portrait and landscape orientations. 我有很多子视图,每个子视图都有自己的图形,纵向和横向都不相同。 When should I load the new graphics when the orientation changes?
方向改变时应何时加载新图形?
If shouldn't be layoutSubviews, I don't also like the idea of reloading resources in view from UIViewController, because of complicated view hierarchy that I have (it would require to pass this information down). 如果不应该是layoutSubviews,那么我也不喜欢从UIViewController重新加载视图资源的想法,因为我拥有复杂的视图层次结构(需要将这些信息向下传递)。
There is also option to register in NSNotificationCenter for orientation changes in each view, and load new resources when it changes. 还可以选择在NSNotificationCenter中注册以在每个视图中更改方向,并在更改时加载新资源。 But I don't quite like it either, because I believe that there should be mechanism in iOS that enables that.
但是我也不太喜欢它,因为我认为iOS中应该有启用该功能的机制。 Or, maybe I should think in a different way, and build different views for portrait and landscape...
或者,也许我应该以不同的方式思考,为肖像和风景建立不同的看法...
What do you suggest? 你有什么建议?
I would have your subviews all extend a custom view class that has a -setOrientation:
method that swaps between the portrait and landscape graphics. 我希望您的子视图全部扩展自定义视图类,该类具有
-setOrientation:
方法,可在纵向和横向图形之间交换。 Then in your view controller I would override -willRotateToInterfaceOrientation:duration:
and add a loop that sets the orientation for all of the children, thereby causing the graphics to swap when the orientation changes. 然后在您的视图控制器中,我将重写
-willRotateToInterfaceOrientation:duration:
并添加一个循环,该循环为所有子代设置方向,从而在方向更改时导致图形交换。
I think that's the most straighforward way to do it. 我认为这是最简单的方法。 Using NSNotificationCenter could be tricky and you're left without a guarantee that every child will get the notification.
使用NSNotificationCenter可能会很棘手,您将无法保证每个孩子都会收到通知。
Anyway, that's how I'd do it. 无论如何,这就是我要做的。 Let me know if you need examples.
让我知道您是否需要示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.