Ios 如何在Swift中缩放动画GIF?

Ios 如何在Swift中缩放动画GIF?,ios,swift,animation,autolayout,gif,Ios,Swift,Animation,Autolayout,Gif,我正在使用这个功能来制作这个repo的GIF动画,效果很好 我的问题是,我不知道如何在场景中缩放它以处理多个iOS设备。似乎所有的动画都是在代码中完成的,我想知道是否有办法将其连接到故事板中的UIImageView,以便使用自动布局 import UIKit import SpriteKit class TitlePage: UIViewController { @IBOutlet weak var animation: UIImageView! override func

我正在使用这个功能来制作这个repo的GIF动画,效果很好

我的问题是,我不知道如何在场景中缩放它以处理多个iOS设备。似乎所有的动画都是在代码中完成的,我想知道是否有办法将其连接到故事板中的UIImageView,以便使用自动布局

import UIKit
import SpriteKit

class TitlePage: UIViewController {

    @IBOutlet weak var animation: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        //Add the bouncing ball GIF
        var imageData = NSData(contentsOfURL: NSBundle.mainBundle()
            .URLForResource("Bouncing Ball", withExtension: "gif")!)
        let bouncingBall = UIImage.animatedImageWithData(imageData!)
        var animation = UIImageView(image: bouncingBall)
        //view.addSubview(animation)
    }

}

我只是举了个例子,没有任何问题。
我做了以下工作:

1. Created a Single-View Swift application project.
2. Added the UIImage+Gif.swift file to the project.
3. Added the adventure-time.gif file to the project.
4. In the Storyboard editor dragged a UIImageView to the middle of the main view.
5. Created an outlet for the UIImageView and named it "gifView".
6. Set constraints to center gifView horizontally and vertically.
7. Set more constraints to set gifView's H and W to 0.6 x container H and W.
8. In the ViewController added the following line to viewDidLoad():

gifView.image = UIImage.gifWithName("adventure-time")
就这样。工作正常。

将其包装到IBDesignable类中是留给读者的练习。

您能分享您的代码吗?是的,很抱歉。在Git Repo中,有一个例子,但他似乎是在CGRect中硬编码值,这在较小iOS设备的模拟器上无法很好地扩展。我假设您已经用UIImageView设置了情节提要,所以与其创建新的UIImageView实例并将其添加为子视图,只需在现有动画UIImageView上设置bouncingBall UIImage,如果我这样做,它不会设置GIF动画。我得到一个静态图像。