我正在使用UIPageViewController,并且有一个数组的ViewControllers
lazy var subviewControllers: [UIViewController] = {
return[
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController1") as! ViewController1,
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController2") as! ViewController2,
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController3") as! ViewController3
]
}()
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let subview3 = subviewControllers[2] as? ViewController3 {
subview3.customBar.alpha = 0.8 // <- error on this line
}
}
但是有时在滚动时会出现此错误:
在展开可选值时意外发现nil