iphone/ipad 方向处理 [英] iphone/ipad orientation handling

查看:17
本文介绍了iphone/ipad 方向处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is more of a general question for people to provide me guidance on, basically Im learning iPad/iPhone development and have finally come across the multi-orientation support question.

我查了很多 doco,我的书Beginning iPhone 3 Development"有一个很好的章节.

I have looked up a fair amount of doco, and my book "Beginning iPhone 3 Development" has a nice chapter on it.

但我的问题是,如果我要以编程方式更改我的控件(甚至为每个方向使用不同的视图),人们究竟如何维护他们的代码库?我可以想象意大利面条式代码/数以千计的if"检查有很多问题,这会让我发疯,对 UI 安排做一个小的改变.

But my question is this, if I was to programatically change my controls (or even use different views for each orientation) how on earth to people maintain their code base? I can just imagine so many issues with spaghetti code/thousands of "if" checks all over the place, that it would drive me nuts to make one small change to the UI arrangement.

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

Does anyone have experience handling this issue? What is a nice way to control it?

非常感谢标记

推荐答案

我在我的视图控制器中使用两个简单的方法来做到这一点:

I do this with two simple methods in my 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);
        ...
    }
}

为了保持清洁,您可以轻松划分视图调整/重新加载/等.使用从单个 if-else 条件中调用的方法.

To keep this clean you could easily compartmentalize the view adjustments/reloading/etc. with methods called from inside the single if-else conditional.

这篇关于iphone/ipad 方向处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆