UIImageView动画中的错误

时间:2015-02-17 04:42:38

标签: ios swift uiimageview

Absolute 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

类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...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 个答案:

答案 0 :(得分:2)

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

第1期

要修复has no initializers,您需要在班级中至少实现一个init函数。

第2期

要修复IBOutlet has non-optional,您需要将IBOutlet变量更改为选项。

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

第3期

用于修复[UIImage] is not identical to UInt8+=不能用于将UIImage附加到[UIImage]

您需要更改:

imageList += UIImage(named: imageName)

imageList.append(UIImage(named: imageName))