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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:41:47+00:00 2026-06-17T06:41:47+00:00

I have a UIImageView that is set to move up and down the screen

  • 0

I have a UIImageView that is set to move up and down the screen with the value of the accelerometer, using the following code:

ship.center = CGPointMake(ship.center.x, ship.center.y+shipPosition.y);

Where shipPosition is a CGPoint set in the accelerometerDidAccelerate method using:

shipPosition.y = acceleration.x*60;

Obviously this works fine, it is very simple. I run into trouble when I try to something equally simple, vary the rotation of the image depending on its acceleration. I do this using:

ship.transform = CGAffineTransformMakeRotation(shipPosition.y);

For some reason this causes a very strange thing to happen, in that the image snaps back to its origin every time the main method is called. I can see frames where the image moves to where it should be, but then instantly snaps back.

This problem only happens when I have the rotation line in, commented out it works fine. I have no idea what is going on here, I have done this many times for different apps and i never had such a problem. In fact I copied my code from a different app I created where it works fine.

EDIT:

What really confuses me is when I change the angle of the rotation from the acceleration to the position of the ship using:

ship.transform = CGAffineTransformMakeRotation(ship.center.y/10);

When I do this, the ship actually rotates based on the accelerometer but does not move, which is crazy because a changing ship.center.y means the position of the ship is changing, but it’s not!!

  • 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-06-17T06:41:48+00:00Added an answer on June 17, 2026 at 6:41 am

    You should set the transform of you view back to CGAffineTransformIdentity before you set his center coordinates or frame and after that apply the new transformation.

    The frame property returns the transformed coordinates of a view if it is transformed and not the true (well actually the transformed are true) coordinates.

    Quote from the docs:

    Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.


    Update/Actual Answer:
    Well the actual problem is

    shipPosition.y = acceleration.x*60;
    

    Since you set the y pos in accelerometerDidAccelerate.
    The acceleration won’t remember it’s old value. So if you move your device it will get a peak and as you slow down it will decelerate again.

    Your ship will be +/-60 at the highest acceleration speed but will be 0 when you stop moving your device and shipPosition.y will be 0.

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

Sidebar

Related Questions

I have a custom UITabvleViewCell that has a UIImageView in it. I can set
I have an app that will show some images using UIImageView, now I want
I have the following code: UIImageView *photo = [[[UIImageView alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x+130, title_bar.titleView.frame.origin.y-12, 22.0, 22.0)]
I have a UIImageView that I dynamically load with an Image using myTableViewCell.myImageView.image =
Using XCode 4.4 and Mountain Lion, I have a UIImageView, and on that view,
I have a UIImageView that starts off with an image (loading.png) specified in IB.
I have a UIImageView that is displaying a series of pictures as an animation.
I have a UIImageView that is housed inside a UIScrollView . The image in
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
I have a UIImageView object that when clicked it will play a animation, I

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.