简体   繁体   English

iOS:如何在UIImageView中移动图像

[英]iOS: How to move an image inside a UIImageView

I have an UIImageView that's showing part of an image. 我有一个UIImageView ,它显示图像的一部分。 Is there a way that I can animate the UIImageView so that the image in it moves? 有没有一种方法可以使UIImageView动画化,以便其中的图像移动? So I wish to have my UIImageView stay in it's position but the image in it move. 因此,我希望UIImageView保持在原位置,但其中的图像会移动。 Any way of doing it? 有什么办法吗?

No, but the way you usually do this is by adding your UIImageView to a UIScrollView . 不,但是通常的方法是将UIImageView添加到UIScrollView Make the scroll view as large as you want the displayed image to be but make its contentSize and the image view in it as large as they need to be. 使滚动视图与要显示的图像一样大,但使它的contentSize和其中的图像视图与所需的一样大。

Now you can animate the scroll position of the scroll view to smoothly animate the image position / crop. 现在,您可以为滚动视图的滚动位置设置动画,以平滑地为图像位置/裁剪设置动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM