【发布时间】:2015-12-02 14:02:31
【问题描述】:
我正在使用该功能从这个 repo 制作 GIF 动画,它工作正常。 https://github.com/bahlo/SwiftGif
我的问题是我不知道如何在我的场景中缩放它以处理多个 iOS 设备。似乎所有的动画都是在代码中完成的,我想知道是否有办法将它连接到 Storyboard 中的 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)
}
}
【问题讨论】:
-
你能分享你的代码吗?
-
是的,很抱歉。在 Git Repo 中,有一个示例,但他似乎在 CGRect 中硬编码值,并且在较小的 iOS 设备的模拟器上无法很好地扩展。
-
我假设你已经用你的 UIImageView 设置了故事板,所以不要创建一个新的 UIImageView 实例并将其添加为子视图,只需在现有动画 UIImageView 上设置 bouncingBall UIImage跨度>
-
如果我这样做,它不会为 GIF 设置动画。我得到一张静态图片。
标签: ios swift animation autolayout gif