0

嗨,我有这样的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];         

    // Get view bounds
    CGRect bounds = [self.view bounds];

    // Get center point
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width/2.0;
    center.y = bounds.origin.y + bounds.size.height/2.0;


    NSLog(@"center y = %f", center.y);



}

上面的日志最初打印274.0

然后我有这个方法:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)x
                                         duration:(NSTimeInterval)duration
{

    CGRect bounds = [[self view] bounds];

    // Get center point
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width/2.0;
    center.y = bounds.origin.y + bounds.size.height/2.0;


    // If the orientation is rotating to Portrait mode...
    if (UIInterfaceOrientationIsPortrait(x))
    {
         NSLog(@"In rotation, center y = %f", center.y);      

    }


}

正如您center.y可能注意到的,上述方法中的计算方式与 viewDidLoad 中的计算方式相同。但是,当手机首先旋转到横向然后回到纵向时,现在center.y上面的方法总是打印 230(而不是最初的 274.0) - 为什么?这可能是什么原因造成的?

4

1 回答 1

0
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    CGRect bounds = [[self view] bounds];
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width/2.0;
    center.y = bounds.origin.y + bounds.size.height/2.0;
    if (UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)){
        NSLog(@"In rotation, center y = %f", center.y);
    }
}
于 2013-07-26T09:01:58.043 回答