change position of the UIImageView

2019-04-08 04:44发布

问题:

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?

回答1:

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!");
                 }];


回答2:

self.psView.frame = CGRectMake(self.wvView.frame.origin.x, self.wvView.frame.origin.y, self.psView.frame.size.width, self.psView.frame.size.height);