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

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

问题描述

这是一个普遍的问题,人们可以为我提供指导,基本上我正在学习iPad / iPhone开发,并且终于遇到了多方位支持问题。



<我查了相当数量的doco,我的书开始iPhone 3开发有一个很好的章节。



但我的问题是这个,如果我是以编程方式改变我的控件(甚至为每个方向使用不同的视图),人们如何维护他们的代码库?我可以想象很多问题与意大利面条代码/成千上万的如果检查到位,它会让我疯狂地对UI安排做一个小改动。



有没有人有处理此问题的经验?控制它的好方法是什么?



非常感谢
Mark

解决方案

我在视图控制器中使用两个简单方法执行此操作:

   - (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 条件内部调用的方法。


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.

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

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?

Thanks a lot Mark

解决方案

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

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天全站免登陆