这更像是一个一般性问题,供人们为我提供指导,基本上我正在学习 iPad/iPhone 开发,并最终遇到了多方向支持问题。
我查阅了大量的 doco,我的书《Beginning iPhone 3 Development》中有一个很好的章节。
但我的问题是,如果我要以编程方式更改我的控件(或者甚至为每个方向使用不同的视图),人们到底如何维护他们的代码库?我可以想象意大利面条代码有这么多问题/到处都是数千个“if”检查,如果对 UI 安排做出一点小小的改变,我就会发疯。
有人有处理这个问题的经验吗?有什么好的方法可以控制它吗?
多谢
标记
我在视图控制器中使用两个简单的方法来执行此操作:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
titleImageView.center = CGPointMake(235.0f, 42.0f);
subtitleImageView.center = CGPointMake(355.0f, 70.0f);
...
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
titleImageView.center = CGPointMake(160.0f, 52.0f);
subtitleImageView.center = CGPointMake(275.0f, 80.0f);
...
}
}
为了保持干净,您可以轻松地划分视图调整/重新加载等。从单个内部调用的方法if-else
有条件的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)