Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 和坐标有点混淆_Objective C - Fatal编程技术网

Objective c 和坐标有点混淆

Objective c 和坐标有点混淆,objective-c,Objective C,嗨,我有这样的代码: - (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 = bou

嗨,我有这样的代码:

- (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)——为什么?
什么原因会导致这种情况?

有没有理由不使用self.view.center或至少是
cRectgetMidy(bounds)
?还有,你是在想
bounds
还是
frame
?嗨,大卫,我不确定你的意思,只是我的问题是,由于center.y在viewDidLoad和WillAnimateRotationInterfaceOrientation中的计算方式相似,因此它们在这些方法中为什么不同?(旋转发生后,首先是横向旋转,然后是纵向旋转)??自动调整大小?会旋转还是会旋转?@David Rönnqvist:我不太清楚你的意思,也不清楚这与我在帖子中提到的计算
center.y
有什么关系
- (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);
    }
}