Reputation: 1041
I have a problem with performance on iPad. I need to drag UIView with animation. It's like self made UIScrollView, but with bigger bounce effect.
I use self made animation cycle with NSTimer (scheduletTimerWithInterval 0.3 sec). On each iteration I move view step by step.
But the problem is that it's freeze time to time. Not too much... but enough to feel.. Do anyone knows any approaches to do following thing in correct way, so it will work as charm?
Thanks in advance!
Upvotes: 0
Views: 299
Reputation: 3389
Perhaps the timer causes your problem. The interval of animations should be something like that: 1.0/60.0f
Upvotes: 0
Reputation: 1699
You should use [UIView beginAnimations] instead of the scheduled timer. For example, to move something over 2 seconds, you could do something like this:
YourView.center = CGPointMake(0,0);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
YourView.center = CGPointMake(30, 30);
[UIView commitAnimations];
This will move YourView from 0,0 to 30,30 over 2 seconds (that's what the setAnimationDuration is for). So you would have a sequence of these if you wanted to do a bounce effect. You can also be notified when the animation completed by using
[UIView setAnimationDidStopSelector:@selector(somefunction)]
at which point you could kick off another animation in your function "somefunction".
Upvotes: 1