gpt4 book ai didi

iPhone/iPad 方向处理

转载 作者:行者123 更新时间:2023-12-03 18:14:46 25 4
gpt4 key购买 nike

这更像是一个一般性问题,供人们为我提供指导,基本上我正在学习 iPad/iPhone 开发,并终于遇到了多方向支持问题。

我查阅了大量的 doco,我的书《Beginning iPhone 3 Development》中有一个很好的章节。

但我的问题是,如果我要以编程方式更改我的控件(甚至为每个方向使用不同的 View ),人们到底如何维护他们的代码库?我可以想象意大利面条代码有这么多问题/到处都是数千个“if”检查,这会让我发疯,对 UI 安排做出一个小小的改变。

有人有处理这个问题的经验吗?有什么好的方法可以控制它吗?

非常感谢标记

最佳答案

我在 View Controller 中使用两个简单的方法来做到这一点:

- (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);
...
}
}

为了保持干净,您可以轻松地划分 View 调整/重新加载等。从单个 if-else 条件内部调用的方法。

关于iPhone/iPad 方向处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2815802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com