Question

I have this code that can slide to left if swiped

[UIView animateWithDuration:1.0 delay:2.0 options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^
    {
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(faceRight:finished:context:)];
        self.bug.center = CGPointMake(75, 200);
    }
        completion:^(BOOL finished)
        {
            NSLog(@"Move to left done");

        }
 ];

but I want to add 1 bounce effect, maybe add a code like:

self.bug.center = CGPointMake(78, 200);

but I dont know how to add this code, where should I write this? I'm new to animations. please help :)

Was it helpful?

Solution

-(void)onTimer 
{
ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);

if(ball.center.x > 320 || ball.center.x < 0)

pos.x = -pos.x;

if(ball.center.y > 460 || ball.center.y < 0)

pos.y = -pos.y;

}


-(your method)

{

 pos = CGPointMake(14.0,7.0);

[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

}

OTHER TIPS

You should use the block based animation methods, it says in the documentation that using blocks is the recommended way. Also, in iOS 7, UIView has a new +method that will do just that. Or you can use the UIkit Dynamics system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top