Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 397
Bob Avatar asked Nov 11 '12 17:11

Bob


2 Answers

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!");
                 }];
like image 99
Srikar Appalaraju Avatar answered Nov 09 '22 12:11

Srikar Appalaraju


self.psView.frame = CGRectMake(self.wvView.frame.origin.x, self.wvView.frame.origin.y, self.psView.frame.size.width, self.psView.frame.size.height);
like image 30
Romin Dhameliya Avatar answered Nov 09 '22 12:11

Romin Dhameliya