Objective c CGRect和CGRect使人产生客观怀疑

Objective c CGRect和CGRect使人产生客观怀疑,objective-c,ios,cocoa-touch,orientation,cgrect,Objective C,Ios,Cocoa Touch,Orientation,Cgrect,我在willrotatetointerfaceorientation方法中使用以下代码 if(UIDeviceOrientationIsLandscape(toInterfaceOrientation)) { NSLog(@"willRotateToInterfaceOrientation landscape"); self.textFieldResult.frame = CGRectMake(146, 210, 97, 31); self.operationLabel

我在willrotatetointerfaceorientation方法中使用以下代码

if(UIDeviceOrientationIsLandscape(toInterfaceOrientation))
{
    NSLog(@"willRotateToInterfaceOrientation landscape"); 
    self.textFieldResult.frame = CGRectMake(146, 210, 97, 31);
    self.operationLabel.frame = CGRectMake(73, 210, 120, 21);
}
else if (UIDeviceOrientationIsPortrait(toInterfaceOrientation))
{
    NSLog(@"willRotateToInterfaceOrientation Portrait");   

    self.textFieldResult.frame = CGRectMake(305, 134, 97, 31);
    self.operationLabel.frame = CGRectMake(82, 138, 120, 21);
}
如果将lanscape旋转一次,也就是说,将lanscape旋转到“纵向”,或者将lanscape旋转到“纵向”。但是,如果我从肖像改为倒立,视图的方向就会受到干扰!控件正在插入else块,但方向不是它应该的方向

我假设的是,对于CGRect,视图的原点是相对于父视图的左上角指定的。这是窗户本身

此外,我在这里指定的坐标与我在故事板上看到的完全不同,我的意思是几乎两倍或一半! 如果我想在ViewWillAspect方法中使用相同的代码(如上所述),那么我必须为相同的视图位置使用不同的坐标集,这些坐标类似于我在故事板上看到的坐标


我想我可能不清楚CGRect的工作原理和相应的函数。

您可以在该视图上使用CGAffineTransform来解决该问题。欲了解更多信息,请访问:和