change position of the UIImageView

匆匆过客 提交于 2019-12-06 01:17:52

问题


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);


来源:https://stackoverflow.com/questions/13333361/change-position-of-the-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!