开发者

iPhone orientation - two boxes

My iPhone app has two boxes with content. When user switch the orientation of a phone boxes change the position like this:

Portrait开发者_如何学Python

|---------|
| BUTTON1 |
| BUTTON2 |
|---------|
|         |
| BUTTON3 |
| BUTTON4 |
|         |
|---------|

Landscape

|---------|---------------|
| BUTTON1 |    BUTTON3    |
| BUTTON2 |    BUTTON4    |
|---------|---------------|

What is the right way to go? Two XIBs, other tricks? Should I resize elements manually in code?


Use something like this:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait){
    button.frame = CGRectMake(20,20,125,125);
    }else{
    button.frame = CGRectMake(20,20,125,125);
    }
}

Of course you'll have to use your own dimensions in the CGRectMake box, but other than that, I hope this helps.


You can use this method in your view controller:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

To adjust the boxes'/views' frames. I believe they will be animated automatically.

Check the docs for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜