ios 改变 UIImageView 的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13333361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:10:10  来源:igfitidea点击:

change position of the UIImageView

objective-ciosxcodeanimationuiimageview

提问by Boban

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

如何为 UIImageView 做一个简单的位置更改。假设当前坐标是 x: 20 和 y:30

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

我想将它移动到 x:100 和 y:100。

Is it possible to do animation of movement?

是否可以制作运动动画?

回答by Srikar Appalaraju

You need to change the CGFrame of that UIImageViewLike so -

您需要UIImageView像这样更改 CGFrame -

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

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

This changes the uiimageviewpoistion 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 :)

这将改变uiimageview位置,(100, 100)同时保持高度和宽度相同。请注意,您不仅可以使用上面的代码更改(x,y)位置,还可以更改视图的大小。使用以下代码,您也可以为其设置动画:)

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

回答by Romin Dhameliya

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