bla0009 bla0009 - 3 months ago 23
iOS Question

change position of the UIImageView

How can I do a simple position changing for UIImageView. Lets say that current coordinates are x: 20 and y:30

I want to move it to x:100 and y:100.

Is it possible to do animation of movement?

Answer

You need to change the CGFrame of that UIImageView Like so -

[imageView setFrame:CGRectMake(100, 100, imageView.frame.size.width, imageView.frame.size.height)];

This changes the uiimageview poistion to (100, 100) while keeping the height and width same. Note that you can use the above code to not only change the (x,y) position but also the size of the view. Using the below code you can animate it too :)

If you want to animate the position change -

[UIView animateWithDuration:0.35 
                      delay:0.0  
                    options: UIViewAnimationCurveEaseOut
                 animations:^{ 
                     [imageView setFrame:CGRectMake(100, 100, imageView.frame.size.width, imageView.frame.size.height)];
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
Comments