Moeit
Moeit

Reputation: 67

xcode image position x y update realtime

I am trying to move an imageView according to coordinates I get in realtime from the server. The movement of the image is lagging, if I use a CGPath instead of an imageView it is very smooth so the issue is not from the server.

Is there a better efficient way to move an imageView by updating its X and Y continuously.

I am using the code below to update the imageView coordinates.

imgView.frame=CGRectMake(x-70/2, y-70/2, 70, 70);

Upvotes: 0

Views: 339

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

Use UIView's animation APIs:

[UIView animateWithDuration:0.5
                 animations:^{
                     imgView.frame = CGRectMake(x-70/2, y-70/2, 70, 70);
                 }
                 completion:nil];

Upvotes: 1

Related Questions