风景模式UIView.center给出了Potrait模式坐标

问题描述:

好吧,这是我的困境,我发现这很奇怪,而且我很无知。我有一个应用程序,它运行在横向模式下,当我在手机上进行调试时,我将其保持横向模式。我从我的主视图控制器上的UIView获取中心值,我需要这个将项目放在屏幕中心,因为它是通用的,所以我需要这个值是可变的,而不是设置为iPhone屏幕大小。风景模式UIView.center给出了Potrait模式坐标

当我做到这一点,并宣读了由CGPoint返回view.center x和y我得到 X = 170 Y = 240

的代表是在我的应用程序的一个视图控制器,中心功能我想移动到中心的一个对象。

- (void) center 
{ 
    CGPoint center = ((UIViewController*)delegate).view.center; 
    CGSize size = self.frame.size; 
    double x = center.x - size.width/2 - location.x; 
    double y = center.y - size.height/2 - location.y; 

    [self _move:1.0 curve:UIViewAnimationCurveEaseInOut x:x y:y]; 
} 

- (void)_move: (NSTimeInterval)duration 
      curve:(int)curve x:(CGFloat)x y:(CGFloat)y 
{ 
    // Setup the animation 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:duration]; 
    [UIView setAnimationCurve:curve]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    // The transform matrix 
    CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y); 
    self.transform = transform; 

    // Commit the changes 
    [UIView commitAnimations]; 

} 

现在对我来说这没有多大意义。有任何想法的人如何解决这个问题?

+0

[UIView width and height reversed]的可能重复项(http://*.com/questions/8141278/uiview-width-and-height-reversed) – jrturton

使用边界,而不是帧。框架位于超视图的坐标系中,对于您的根视图而言,该坐标系是窗口 - 这不会以不同的方向旋转。

界限在视图自己的坐标系中,因此在设置子视图的中心时使用适当的矩形,因为中心也在超视图的坐标系中表示。