Placing and Moving Views on Rotation (UIView)

前端 未结 4 852
失恋的感觉
失恋的感觉 2020-12-28 08:40

What\'s the \"correct\" way of exactly placing and moving views when an app rotates? That is, how can I have fine-grained control of the position, size, and reflow of my vie

4条回答
  •  梦谈多话
    2020-12-28 09:36

    Here's one idea. I worry that the animations will work funny, but try it and see.

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
                                    duration:(NSTimeInterval)duration {
    
        if (toOrientation == UIInterfaceOrientationLandscapeLeft ||
            toOrientation == UIInterfaceOrientationLandscapeRight) {
            [UIView beginAnimations:nil context:NULL]; {
                [UIView setAnimationDuration:1.0];
            }
                [UIView setAnimationDelegate:self];
            [viewA setFrame:CGRectMake(?,?,?,?)];
            [viewB setFrame:CGRectMake(?,?,?,?)];
            [viewC setFrame:CGRectMake(?,?,?,?)];
            } [UIView commitAnimations];    
        } else if  (toOrientation == UIInterfaceOrientationPortrait ||
                toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            [UIView beginAnimations:nil context:NULL]; {
                [UIView setAnimationDuration:1.0];
            }
            [UIView setAnimationDelegate:self];
            [viewA setFrame:CGRectMake(?,?,?,?)];
            [viewB setFrame:CGRectMake(?,?,?,?)];
            [viewC setFrame:CGRectMake(?,?,?,?)];
            } [UIView commitAnimations];    
        }
    

提交回复
热议问题