开发者

translation after rotation view using CGAffine

I have a view that contain some textfield. I set view's orientation like this

(void)deviceRotated开发者_StackOverflow:(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??


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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜