旋转问题,在自定义 TabBarController 中管理子视图
我正在实现一个自定义 TabBarViewController
,除了设计之外,它应该具有相同的行为。
我在数组中管理我的 subViewControllers
,按照“开始 Iphone 开发”第 6 章中所述,通过延迟加载来初始化视图,这是通过用尽可能多的 NSNull
对象填充我的数组来实现的作为我拥有的选项卡,并在需要时用新初始化的 viewControllers 替换它们。
这样我就可以跟踪视图的正确顺序并将它们与正确的选项卡相关联(数组中的第一个位置保留给第一个视图等)。
切换视图时,使用 [currentViewController.view removeFromSuperview];
删除当前视图,并使用 [self.view addSubview:newViewController.view];
添加新视图。现在以前的视图保留在数组中以供将来使用。
旋转设备时会出现困难,因为(我认为)我的数组中未使用 addSubview
添加到超级视图的 viewControllers
没有被旋转,这我想有点道理。
结果是,当旋转之后,例如到横向模式,用户切换到他之前已经去过的视图,这是因为已经初始化的视图,该视图仍然以纵向模式呈现给他。
我的问题是:
1)我是否必须手动旋转未添加的子视图,如果需要,如何最简单地完成此操作?
2)普通的 TabBarController
如何管理它的控制器,换句话说,我做得对吗?
I am implementing a custom TabBarViewController
, that apart from the design should have the same behavior.
I manage my subViewControllers
in an array, initializing views with lazy loading as described in "Beginning Iphone Development" Chapter 6, which I do by filling my array with as many NSNull
objects as tabs I have and replacing them with freshly initialized viewControllers
when needed.
This way I can keep track of the right order of views and associating them with the right tabs (the first place in the array is reserved for the first view etc).
When switching views, the current view is removed with [currentViewController.view removeFromSuperview];
and a new one is added with [self.view addSubview:newViewController.view];
. The now former view is preserved in the array for future use.
A difficulty arrises when rotating the device, because (I think) the viewControllers
in my array that are not added to the superview at that moment with addSubview
are not being rotated, which kind of makes sense, I guess.
The result is that when after rotation, e.g. to landscape mode, the user switches to a view that he has already been before, which is because of that already initialized, the view is presented to him still in portrait mode.
My questions are then:
1) Do I have to rotate my non-added subviews manually and if so, how is this done easiest?
2) How does the normal TabBarController
manage its controllers, in other words, am I doing it right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不尝试更改视图控制器的视图属性的框架以适应用户当前所处的模式(纵向或横向)
所以在shouldAutoRotateToInterfaceOrientation中只需更改yourviewcontroller.view.frame = CGRectMake(x,y,width,height) )也许你会得到旋转的视图!
我希望它有帮助
Why dont you try changing the frame of your view controller's view property for the current mode that the user is in (Potrait or landscape)
So in shouldAutoRotateToInterfaceOrientation just change yourviewcontroller.view.frame = CGRectMake(x,y,width,height) and perhaps you will have your rotated views!!
I hope it helps