ImageView图像动画应用程序崩溃开始[SWIFT]

时间:2015-10-21 12:09:45

标签: ios swift exception uiimageview

我试图让这些图像动画,但模拟器一直在开始碾压,有人可以建议 - 我做错了什么? 这是我的ViewController.swift的样子:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var ImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        var imagesListArray: [UIImage] = []
        for name in ["img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg"] {
            if let image = UIImage(named: name) {
                imagesListArray.append(image)
            }
        }
        ImageView.animationImages = imagesListArray;
        ImageView.animationDuration = 5
        ImageView.startAnimating()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

我肯定有导入的图像(虽然这不会是问题,即使我没有)。那么,还有什么呢?

这里我将添加我开始时的异常日志:

2015-10-21 15:05:47.168 singleVshow[11922:7207193] -[UIView setAnimationImages:]: unrecognized selector sent to instance 0x7fa119531770
2015-10-21 15:05:47.172 singleVshow[11922:7207193] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[UIView setAnimationImages:]: unrecognized selector sent to instance 0x7fa119531770'

libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

如有必要,我会添加调用堆栈。

2 个答案:

答案 0 :(得分:0)

使用此代码的代替而不是你的代码

override func viewDidLoad() {
    super.viewDidLoad()
    var imagesListArray: NSMutableArray = NSMutableArray()
    for name in ["img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg"] {
        if let image = UIImage(named: name) {
            imagesListArray.add(image)
        }
    }
    ImageView.animationImages = imagesListArray;
    ImageView.animationDuration = 5
    ImageView.startAnimating()
}

答案 1 :(得分:0)

错误表明它是一个试图调用setAnimationImages的UIView对象。您可能需要验证故事板中UIImageView的插座是否设置正确。您可能只想完全删除插座并重新创建它,以确保选择UIImageView。