简体   繁体   English

UIImageView从左到右查看图像

[英]UIImageView view Image from Left to Right

So I have a big image in an UIImageView (Swift) with "Aspect Fill" 因此,我在UIImageView(Swift)中使用“ Aspect Fill”添加了一个大图像

But What I want is to have like an Animation or Ken Burn Effect on the Image. 但是我想要的是对图像具有动画或Ken Burn效果。

In the Image Below... What I want is to go from Red to Yellow seen the image. 在下面的图像中...我想要的是从红色到黄色看到的图像。

在此处输入图片说明

原始图片

UIImageView

Take a normal uiview give it proper height width as per ur wish... Take an imageview inside of it and give the height, x coordinate and y coordinate same as uiview and keep the width as much wide you want to keep the image.... 取一个普通的uiview,按照您的意愿给它适当的高度宽度...在其中取一个imageview,并给它的高度,x坐标和y坐标与uiview相同,并保持想要的宽度。 ..

Use UIView.animateWithDuration method and in its animation block set the final desired frame such that the end of image view comes equal to the end of uiview... The image view will slide outside of vision of the uiview as you desire... 使用UIView.animateWithDuration方法,并在其动画块中设置最终所需的帧,以使图像视图的末尾等于uiview的末尾...图像视图将根据需要滑到uiview的视野之外...

You can even repeatedly animate from left to right calling animation into each others completion block 您甚至可以从左到右反复制作动画,以将动画调用到彼此的完成块中

I found an extension for UIImageView called UIImageViewAligned . 我发现UIImageView的扩展名为UIImageViewAligned You can use the alignment properties provided by the extension and animate the changes. 您可以使用扩展名提供的对齐属性并为更改设置动画。

import UIKit
import UIImageViewAligned

class ViewController: UIViewController {

    // MARK: Outlets

    @IBOutlet var imageView: UIImageViewAligned!

    // MARK: Lifecycle

    override func viewDidLoad() {

        super.viewDidLoad()

        imageView?.contentMode = .scaleAspectFill
        imageView?.alignLeft = true
        imageView?.alignRight = false
    }

    override func viewDidAppear(_ animated: Bool) {

        super.viewDidAppear(animated)

        UIView.animate(withDuration: 5) {
            self.imageView?.alignLeft = false
            self.imageView?.alignRight = true
        }
    }
}

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

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