Search code examples
iosrotationtranslationcgaffinetransform

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??


Solution

  • 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