問題描述
使用 CGAffine 旋轉視圖後的平移 (translation after rotation view using CGAffine)
I have a view that contain some textfield. I set view's orientation like this
(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];
}
}
my problem is I want to make that view move upward when the keyboard appear, because some textfields are hidden by the keyboard. I think i have to use CGAffineTransformMakeTranslation, but i dont know how to use it after that rotation.
can somebody help me solve this problem??
參考解法
方法 1:
we can use CGAffineTransformConcat. Here is the code i made to solve this problem
CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0);
CGAffineTransform translate = CGAffineTransformMakeTranslation(-5, -150);
self.alertView.transform = CGAffineTransformConcat(translate, rotate);
but i still not understand, why the translation in portrait orientation && portrait upside down orientation have to use different point x and y. It's happen too in landscape left && landscape right orientation
方法 2:
Here is how to rotate to the right
CGAffineTransform translate = CGAffineTransformMakeRotation(M_PI/18);
view.transform = CGAffineTransformConcat(view.transform, translate);
The, rotate to the left:
CGAffineTransform translate = CGAffineTransformMakeRotation(-M_PI/18);
view.transform = CGAffineTransformConcat(view.transform, translate);
(by R. Dewi、R. Dewi、P.J.Radadiya)