开发者

Rotate main screen and rotate back subview

How can I rotate my base view and still make sure that its subviews are still in their correct locations?

--------                            
|X     |   After 90 degree rotate and stretch
|      |   this should remain the same
|      |
|     Y|
--------

I presume I need to rotate 90 degrees and stretch according to window ratio and perform the opposite on the subview?

The following does not work...

- (void) performTransformation:(UIView*)view isBase:(BOOL)isBase
{
    if(isBase) {
        [view.layer setAffineTransform:CGAffineT开发者_如何学PythonransformConcat(
            CGAffineTransformMakeRotation(M_PI * 0.5),
            CGAffineTransformMakeScale(-(3.0/4.0), (4.0/3.0)))];
    } else {
        [view.layer setAffineTransform:CGAffineTransformConcat(
            CGAffineTransformMakeScale(-(4.0/3.0), (3.0/4.0)),
            CGAffineTransformMakeRotation(-M_PI * 0.5))];
}


Are you rotating in response to the device’s orientation changing? If so, you can just use UIViewController’s -shouldAutorotateToInterfaceOrientation: method to rotate the view.

To do what you're describing, you can set the individual UIViews’ autoresizingMask property. In your example, you'd do the following:

[viewX setAutoresizingMask:(UIViewFlexibleRightMargin |
                            UIViewFlexibleBottomMargin )];

[viewY setAutoresizingMask:(UIViewFlexibleTopMargin |
                            UIViewFlexibleLeftMargin )];

That code will set the first view (which I’ve called viewX) to stay with the top-left corner, and the second view with the bottom-right.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜