2

我有一个包含一些文本字段的视图。我这样设置视图的方向

(void)deviceRotated:(id)sender
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation];

    if (orientation == UIDeviceOrientationPortrait)
    {
        CGAffineTransform affine = CGAffineTransformMakeRotation (0.0);
        [self.View setTransform:affine];
    }

    if (orientation == UIDeviceOrientationPortraitUpsideDown)
    {
        CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 180 / 180.0f);
        [self.View setTransform:affine];
    }
    else if (orientation == UIDeviceOrientationLandscapeLeft)
    {
        CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 90 / 180.0f);  
        [self.View setTransform:affine];
    }
    else if (orientation == UIDeviceOrientationLandscapeRight)
    {
        CGAffineTransform affine = CGAffineTransformMakeRotation ( M_PI * 270 / 180.0f);
        [self.View setTransform:affine]; 
    }
}

我的问题是我想让该视图在键盘出现时向上移动,因为键盘隐藏了一些文本字段。我想我必须使用 CGAffineTransformMakeTranslation,但我不知道在旋转之后如何使用它。

有人可以帮我解决这个问题吗?

4

2 回答 2

8

我们可以使用 CGAffineTransformConcat。这是我为解决此问题而编写的代码

CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0);
CGAffineTransform translate = CGAffineTransformMakeTranslation(-5, -150);
self.alertView.transform = CGAffineTransformConcat(translate, rotate);

但我仍然不明白,为什么纵向和纵向倒置方向的翻译必须使用不同的 x 点和 y 点。它也发生在横向左和横向右方向

于 2010-12-01T08:50:13.693 回答
0

这是向右旋转的方法

CGAffineTransform translate = CGAffineTransformMakeRotation(M_PI/18);
view.transform = CGAffineTransformConcat(view.transform, translate);

向左旋转:

CGAffineTransform translate = CGAffineTransformMakeRotation(-M_PI/18);
view.transform = CGAffineTransformConcat(view.transform, translate);
于 2015-12-28T06:37:55.910 回答