Hi guys I am preety new here.
And I have a UIimageview
.
And I know what is the coordinates of a UITouch
.
Now I want the ball(UIImageView
) to go towards it.
I tried to think of ways to do this...
Using CGPoint
But I cant think on any way that will work properly
How can I do that? (i didnt found answer in the internet)
- (void)viewDidLoad
{
[super viewDidLoad];
[self play];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(play) userInfo:nil repeats:YES];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
ballvelocity = [touch locationInView:self.view];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
ballvelocity = [touch locationInView:self.view];
}
-(void) play{
[UIView animateWithDuration:3 animations:^{
ball.center = CGPointMake(ballvelocity.x, ballvelocity.y);
}];
}