gpt4 book ai didi

ios - 如何在 Swift 中缩放动画 GIF?

转载 作者:行者123 更新时间:2023-11-29 01:40:37 26 4
gpt4 key购买 nike

我正在使用此功能为来自此存储库的 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)
}

}

最佳答案

我只是做了一个例子,没有遇到任何问题。
我做了以下操作:

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 类中是留给读者的练习。

关于ios - 如何在 Swift 中缩放动画 GIF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32431479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com