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 789045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:27:49+00:00 2026-05-14T21:27:49+00:00

I am programming a gauge display for an iphone application: a centered needle UIImageView

  • 0

I am programming a gauge display for an iphone application: a centered needle UIImageView against a fixed background UIImageView. I am new to iPhone programming, and don’t know much about CoreAnimation, but with looking through examples and fiddling with my anchorPoint setting and the position of the needle image against the background in InterfaceBuilder, my needle is coming up with my desired rotation point properly centered against the background:

self.needleIV.layer.anchorPoint = CGPointMake( 0.5, 0.68 );

My test animations work perfectly (the needle remains properly centered in the gauge, and rotates around my desired rotation point, the anchor point), using this code:

CABasicAnimation *rotateAnimation = [CABasicAnimation animation];
rotateAnimation.keyPath = @"transform.rotation.z";
rotateAnimation.fromValue = [NSNumber numberWithFloat:DegreesToRadians( (rand() % 270 - 135) )];
rotateAnimation.toValue = [NSNumber numberWithFloat:DegreesToRadians( (rand() % 270 - 135) )];
rotateAnimation.duration = 4.0;
rotateAnimation.removedOnCompletion = NO;
// leaves presentation layer in final state; preventing snap-back to original state
rotateAnimation.fillMode = kCAFillModeBoth; 
rotateAnimation.repeatCount = 0;
rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

// Add the animation to the selection layer. This causes it to begin animating. 
[self.needleIV.layer addAnimation:rotateAnimation forKey:@"rotateAnimation"];  

The problem is that at application launch the needle comes up initially pointing straight up (which is how the needle looks in the image file), and I can’t figure out how to give it an initial rotation value which doesn’t mess up the animation code. (By “mess up” I mean the needle doesn’t rotate on the correct axis, and becomes uncentered in the gauge).

I’ve tried setting layer.transform to a 3d rotation matrix rotated around the z axis, but this moves the needle off center. I’ve tried this code as well:

[self.needleIV.layer setValue:[NSNumber numberWithFloat:DegreesToRadians(-135.0)] forKeyPath:@"transform.rotation.z"];

which didn’t work either (needle moved off anchorPoint center), and I had high hopes since it’s apparently using the same transform to the working animation code.

I also tried just putting the working animation snippet in my view controller’s viewDidLoad function to “animate” the needle to it’s start location, but it doesn’t do anything at all — apparently the animation doesn’t run until the image is actually up and on the screen, and I’ve confirmed in the debugger that the screen is still black in viewDidLoad.

At this point I’m about to try just hacking in a timer to run an initial animation “long enough” after the app starts to set an animation that rotates the needle properly, but I’d really like to understand what’s going wrong here, and why the animation is apparently rotating around a different axis than is my other attempts at pre-rotation/pre-animation.

  • 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-14T21:27:50+00:00Added an answer on May 14, 2026 at 9:27 pm

    The anchorPoint is relative to the bounds of the parent. Is it possible the bounds of the parent layer/view change after viewDidLoad?

    You should be able to do all this using the UIView center and transform properties, which are 2D so implicitly rotate about the z axis.

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

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok, so I sat down a buddy of mine that… May 14, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer Your code appears correct and you are right to think… May 14, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer Is there an easy way of finding out what the… May 14, 2026 at 10:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.