0

I am wondering if it is possible to take an image view and turn it on the z-axis so that the left side appears closer to the user viewing the application and the right side gets narrower as if it was getting farther away. I was thinking of doing this with OpenGL, but was hoping it could be done with Core Animations. Has anyone had any experience with this?

 UIImageView *front = [[UIImageView alloc] init];
 UIImageView *left = [[UIImageView alloc] init];

 float trialSide = 30 * 5.7;
 front.frame = CGRectMake(180, 280, 360, 295);
 front.image = [img croppedImage:CGRectMake(trialSide, trialSide, imgWidth - (trialSide *2), imgHeight - (trialSide * 2))];
 left.frame = CGRectMake(149, 280, 30, 295);
 left.image = [img croppedImage:CGRectMake(0, trialSide, trialSide, imgHeight - (trialSide * 2))];

 [self.view addSubview:front];
 [self.view addSubview:left];

 CALayer *layer = front.layer;

 CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
 rotationAndPerspectiveTransform.m34 = 1.0 / -1000;
 front.frame = CGRectMake(180, 280, 360, 295);
 rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 30.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
 layer.transform = rotationAndPerspectiveTransform;
 [self.view layoutSubviews];
AgnosticDev
  • 1,843
  • 2
  • 20
  • 36
  • 2
    You will want to apply a perspective transform on the view, take a look at http://stackoverflow.com/questions/347721/how-do-i-apply-a-perspective-transform-to-a-uiview – Chris Wagner Jan 21 '14 at 21:26
  • Excellent, that looks like it will work. One question though, how would I control the length of the view, it looks like it is being shortened when I apply the transform? – AgnosticDev Jan 21 '14 at 21:38
  • 1
    I believe that modifying the layer will not affect the view itself since the layer is a child of the view. If you want to adjust your view's frame based on the new size of the layer you will likely need to do this manually in `layoutSubviews` – Chris Wagner Jan 21 '14 at 21:48
  • OK, thank you. I added some code of what I am trying to do. The translation is working however the views length is still not correct, any idea what I am doing wrong? – AgnosticDev Jan 21 '14 at 21:59

0 Answers0