Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6867261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:17:15+00:00 2026-05-27T03:17:15+00:00

I’m having an odd problem with CATransform3DMakeRotation. When the rotated view is in the

  • 0

I’m having an odd problem with CATransform3DMakeRotation. When the rotated view is in the center of the superview, it looks like this:

Valid XHTML

This is how it’s supposed to look. However, when it’s somewhere else in the superview, say, in the lower left corner, it looks like this:

Valid XHTML

Note that it is tilted to the right. Same thing happens when it’s in the lower right corner, only that it tilts to the left. Is there some way to make it tilt the way it should all the time and in every position? The code to achieve this transformation is as follows:

    CALayer *layer = view.layer;

    CATransform3D aTransform = CATransform3DIdentity;
    float zDistance = 1000;
    aTransform.m34 = 1.0 / -zDistance;  

    self.view.layer.sublayerTransform = aTransform;


    CABasicAnimation *rotateAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
    rotateAnim.fromValue= [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0, 0, 0)];
    rotateAnim.duration=0.12;
    rotateAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(20*M_PI/180, 1, 0, 0)];

    rotateAnim.removedOnCompletion = NO;
    rotateAnim.fillMode = kCAFillModeForwards;
    [layer addAnimation:rotateAnim forKey:@"rotateAnim"];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:17:16+00:00Added an answer on May 27, 2026 at 3:17 am

    You’ve applied perspective at the superview’s layer, and that’s what you’re getting. If you want perspective based on the individual sublayers (without considering the overall perspective), then you have to apply perspective to them individually. For example:

    CALayer *layer = view.layer;
    
    CATransform3D aTransform = CATransform3DIdentity;
    CGFloat zDistance = 2000.;
    aTransform.m34 = 1.0 / -zDistance;  
    
    CABasicAnimation *rotateAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
    
    rotateAnim.fromValue= [NSValue valueWithCATransform3D:aTransform];
    aTransform = CATransform3DRotate(aTransform, 20*M_PI/180, 1, 0, 0);;
    rotateAnim.duration=0.12;
    rotateAnim.toValue=[NSValue valueWithCATransform3D:aTransform];
    layer.transform = aTransform;
    
    [layer addAnimation:rotateAnim forKey:@"rotateAnim"];
    

    In this example, I apply perspective (m34) in both the fromValue and the toValue of the layer. This then gives you perspective relative to an observer standing in front of the layer itself. Your original code had an observer standing in front of the center of the view, and so you get some skew perspective.

    I made some other small changes here. I typically put the observer at 2000 rather than 1000. I find the perspective at 1000 is often more than is desired (unless you’re actively going for strong perspective). Depending on your problem, you might want to get rid of perspective entirely. Don’t apply it just out of habit.

    More importantly, I changed how you were applying the animation at the end. Using removedOnCompletion=NO and kCAFillModeForwards makes things much more complicated than just applying the animation to the model (layer.transform=aTransform) and letting the animation be removed normally. In particular, using removedOnCompletion=NO means that later requests for layer.transform will always return the old value, not the current value. It also makes things complicated if you apply further animations to this layer. This is why the default is to remove the animation when complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.