R. *_*ewi 2 translation rotation cgaffinetransform ios
我有一个包含一些文本字段的视图.我像这样设置视图的方向
(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];
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是当键盘出现时我想让视图向上移动,因为键盘隐藏了一些文本字段.我想我必须使用CGAffineTransformMakeTranslation,但我不知道如何在旋转之后使用它.
有人可以帮我解决这个问题吗?
我们可以使用CGAffineTransformConcat.这是我为解决这个问题而编写的代码
CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0);
CGAffineTransform translate = CGAffineTransformMakeTranslation(-5, -150);
self.alertView.transform = CGAffineTransformConcat(translate, rotate);
Run Code Online (Sandbox Code Playgroud)
但我仍然不明白,为什么纵向和纵向颠倒方向的翻译必须使用不同的点x和y.在横向左侧和横向右侧方向也会发生这种情况
| 归档时间: |
|
| 查看次数: |
6425 次 |
| 最近记录: |