我正在尝试将幻灯片、淡入淡出和增长效果应用于我的 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) yourimageView
with your interface element.
关于ios - 线程 1 : Fatal error: Unexpectedly found nil while unwrapping an Optional value while applying effects to image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47796047/