Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ahan.tm

macrumors regular
Original poster
Jun 26, 2011
141
0
Florida
Hi All,

I am trying to have an array of UIImageViews move with an array. I already am collecting accelerometer data, filtering it with a Low-Pass Filter, and moving the images with an animation, yet the movement is not smooth. I am trying to get movement like the stars in the Starbucks app. Any ideas? Should I be moving to core motion???

Thanks,
Ahan
 
Hi All,

I am trying to have an array of UIImageViews move with an array. I already am collecting accelerometer data, filtering it with a Low-Pass Filter, and moving the images with an animation, yet the movement is not smooth. I am trying to get movement like the stars in the Starbucks app. Any ideas? Should I be moving to core motion???

Thanks,
Ahan


Core motion will give you integrated access to the different sensors on a newer device (accelerometer, gyroscope, GPS, etc.) It won't solve your animation problem.

The problem is likely with what you do to convert your accelerometer data into moving animation.

How are you doing your animation? The devil is in the details as they say.
 
Core motion will give you integrated access to the different sensors on a newer device (accelerometer, gyroscope, GPS, etc.) It won't solve your animation problem.

The problem is likely with what you do to convert your accelerometer data into moving animation.

How are you doing your animation? The devil is in the details as they say.

Here is my code:
Code:
   CGPoint newCenter = CGPointMake(img.center.x + acceleration.x*xFudge,img.center.y - acceleration.y*yFudge);
        
        [UIView animateWithDuration: .001*xFudge
                              delay: 0
                            options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                         animations:^{img.center = newCenter ; img.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);}
                         completion:^(BOOL finished) { }

I am just using the basic UIView Animations. xFudge, yFudge are variables that are randomly selected from 0 to 1.

Thanks,
Ahan
 
Here is my code:
Code:
   CGPoint newCenter = CGPointMake(img.center.x + acceleration.x*xFudge,img.center.y - acceleration.y*yFudge);
        
        [UIView animateWithDuration: [COLOR="Red"].001*xFudge
[/COLOR]                              delay: 0
                            options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                         animations:^{img.center = newCenter ; img.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);}
                         completion:^(BOOL finished) { }

I am just using the basic UIView Animations. xFudge, yFudge are variables that are randomly selected from 0 to 1.

Thanks,
Ahan

If xFudge is in the range 0.0-1.0, then the code shown in red will be a value in the range 0.0 thru 0.001 secs. This places the maximum duration at 0.001 secs, or 1 millisecond, which hardly seems useful.
 
If xFudge is in the range 0.0-1.0, then the code shown in red will be a value in the range 0.0 thru 0.001 secs. This places the maximum duration at 0.001 secs, or 1 millisecond, which hardly seems useful.

I think the iPhone redisplays it's screen 60 times a second.

1/60 of a second is about 0.017. (ok, 0.016666666...)

A duration of .001 is less than 1/10 of a single frame. The system has nothing to work with to create reasonable animations.

You want an animation duration of 10 frames or more in order to get any kind of sense of motion, and even that is probably too short.

Think in terms of much longer animation segments. You can use the UIViewAnimationOptionBeginFromCurrentState option to shift an animation to a new destination value while an animation is "in flight."
 
Hello All,

Thanks for all your responses. I have increased animation duration to .25 seconds, and it seems to have improved. Should I move toward Core Animation to create a better animation effect?

Thanks!
 
Hello All,

Thanks for all your responses. I have increased animation duration to .25 seconds, and it seems to have improved. Should I move toward Core Animation to create a better animation effect?

Thanks!

UIView animation, like you are using, really is Core Animation under the covers. If you drop down to Core Animation you have more options and control, but at the cost of much greated complexity and a much steeper learning curve.

I try to do as much as possible using view animation like you're doing, and only use Core Animation when I can't get the job done with UIView animation. In your case I would think view animation would be enough.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.