横向模式UIView.center提供纵向模式坐标

oph*_*ius 1 iphone uiview ios

我有一个应用程序,它以横向模式运行,我在手机上调试时以横向模式运行它.我从主视图控制器上的UIView中取出中心值,我需要将它放在屏幕中央,因为它是通用的,我需要它是可变的而不是设置为iPhone屏幕尺寸.

当我这样做并从view.center返回的CGPoint中读取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];

}
Run Code Online (Sandbox Code Playgroud)

现在对我来说这没有多大意义.

jrt*_*ton 6

使用边界,而不是框架.框架位于superview的坐标系中,根视图是窗口 - 这不会以不同的方向旋转.

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