ios - 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value while applying effects to image

标签 ios imageview

我正在尝试将幻灯片、淡入淡出和增长效果应用于我的 ImageView 。 以下是我的代码

@IBAction func fadeIn(_ sender: Any) {
    imageView.alpha=0
    UIView.animate(withDuration: 1, animations: {
        self.imageView.alpha=1
    })
}

@IBAction func slideIn(_ sender: Any) {
    imageView.center=CGPoint(x:imageView.center.x-500,y:imageView.center.y)
    UIView.animate(withDuration: 2) {
        self.imageView.center=CGPoint(x:self.imageView.center.x+500,y:self.imageView.center.y)
    }

}

@IBAction func grow(_ sender: Any) {
    imageView.frame=CGRect(x:0,y:0,width:0,height:0)
    UIView.animate(withDuration: 1, animations: {
        self.imageView.frame=CGRect(x:0,y:0,width:200,height:200)
    })
}

每当我点击任何按钮时,我都会得到

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

任何帮助将不胜感激。

最佳答案

(您在问题中提供的信息不完整,因此无法说出问题的确切根源。我可以根据相关信息提出建议)

您的 imageView 应该/可能是一个 IBOutlet 变量/属性,并且您可能尚未将其与 Storyboard/XIB View Controller 界面元素连接起来。

Solution:
Connect (or reconnect) your imageView with your interface element.

enter image description here

关于ios - 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value while applying effects to image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47796047/

相关文章:

java - 我可以在 onPostexecute 中使用 setImageResource 吗?

ios - 应用程序在后台 iOS 时的 Firebase 数据库事务

ios - boundingRectWithSize 不考虑自动换行

ios - Xcode 7 和 Swift 2.0 中的 Fabric 和 Digits pods 工作区失败

java - Android - 在 ImageView 中显示图像 10 毫秒

android:ImageView高度宽度与源图像拟合

php - 我可以在 Swift 的 header 中使用 token 来授权数据库连接吗?

ios - 在 swift3 中结合平移、alpha 和缩放动画

android - 如何使用 JDBC Drive 将 MySql 表图像 (BLOB) 加载到 ImageView

android - 防止 ImageView 将 View 推离屏幕