gpt4 book ai didi

ios - UIImageView 动画错误

转载 作者:行者123 更新时间:2023-11-28 13:17:13 26 4
gpt4 key购买 nike

这里绝对是 Swift 初学者。

我一直在尝试获取一组简单的 png 来制作动画。

这是我的:

I tried to post a screenshot of the errors, but I need at least 10 reputation to post - sorry.

如有任何帮助,我们将不胜感激。

谢谢

#import <UIKit/UIKit.h>
class ViewController: UIViewController {

@IBOutlet var myImageView : UIImageView
@IBOutlet var animationBtn : UIButton
var imageList = UIImage[]()

@IBAction func animationBtnClicked(sender : AnyObject) {
startAnimation()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for i in 1...13
{
let imageName = "\(i)"
imageList += UIImage(named: imageName)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func startAnimation() -> Void
{
if !myImageView.isAnimating()
{
myImageView.animationImages = imageList
myImageView.startAnimating()
animationBtn.setTitle("Stop Animation", forState: UIControlState.Normal)
} else
{
myImageView.stopAnimating()
myImageView.image = UIImage(named:"bomb.jpg")
animationBtn.setTitle("Start Animation", forState: UIControlState.Normal)
}
}

如果对任何人有帮助,这里是调整后的代码。干杯

导入 UIKit

类 View Controller :UIViewController {

@IBOutlet var myImageView: UIImageView!

@IBOutlet var animationBtn: UIButton!
var imageList = [UIImage]()


@IBAction func animationBtnClicked(sender: AnyObject) {
startAnimation()
}



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.


for i in 1...99

{
let imageName = "\(i)"
imageList.append(UIImage(named: imageName)!)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func startAnimation() -> Void

{
myImageView.animationImages = imageList
myImageView.startAnimating()

}

最佳答案

这些错误消息显示了确切的问题。

问题 1

为了修复没有初始化器,您需要在您的类中实现至少一个初始化函数。

问题 2

为了修复 IBOutlet 具有非可选,您需要将您的 IBOutlet 变量更改为可选。

@IBOutlet var myImageView : UIImageView!
@IBOutlet var animationBtn : UIButton!

问题 3

用于修复 [UIImage] 与 UInt8 不相同+= 不能用于将单个 UIImage 附加到 [UIImage]

你需要改变:

imageList += UIImage(named: imageName)

imageList.append(UIImage(named: imageName))

关于ios - UIImageView 动画错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28554756/

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