我正在制作App以通过Scene套件查看3D模型。 Swift 4.0 Xcode 10.1
我想传输图像。我在SCNViewController中创建一个图像(使用SCN View),之后移动到ViewController。我想在传输图像时分割案例。我认为使用Segue会更好。
排列 我在AppDelegate中使用数组。因为我想在ViewController中添加和添加图像。当我移动到其他ViewController时,我不会擦除图像。
当我写下面的时候它会粉碎。我使用了一个func viewWillAppear。 视图控制器
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if appDelegate.isNewSCNStampAdded == true{
let scnstamp = appDelegate.scnstampArray.last!
func returnToTop(segue: UIStoryboardSegue) {
if segue.identifier == "backtoFirstcoma" {
mainImageView.image = scnstamp
mainImageView.contentMode = UIView.ContentMode.scaleAspectFit
print("1")
}else if segue.identifier == "backtoSecondcoma" {
print("2")
}else if segue.identifier == "backtoThirdcoma" {
print("3")
}else {
print("others")
}
}
appDelegate.isNewSCNStampAdded = false
}
}
(第二个想法) 我尝试了另一种方式。我做了一个“分歧”来区分。但这种方式也行不通。我无法在viewWillAppear的时间中看到“分歧”的信息。 视图控制器
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if appDelegate.isNewSCNStampAdded == true{
let scnstamp = appDelegate.scnstampArray.last!
switch dividegoes {
case "goone" :
mainImageView.image = scnstamp
print("1")
case "gotwo" :
secondImageView.image = scnstamp
print("2")
case "gothree" :
thirdImageView.image = scnstamp
print("3")
default:
print("Others")
}
}
appDelegate.isNewSCNStampAdded = false
}
}
SCNViewController
let dividegoes = "gozero"
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.identifier {
case "backtoFirstcoma" :
let whiteVc = segue.destination as! ViewController
whiteVc.dividegoes = "goone"
print("go1")
case "backtoSecondcoma" :
let blueVc = segue.destination as! ViewController
blueVc.dividegoes = "gotwo"
print("go2")
case "backtoThirdcoma" :
let greenVc = segue.destination as! ViewController
greenVc.dividegoes = "gothree"
print("go3")
default:
print(“Others")
}
}
在这种情况下如何划分案件。 如果我删除“if-else”结构,它就会成功。但我需要分三种方式。
错误信息 其视图不在窗口层次结构中!
我无法在viewWillAppear中使用Segue ......?也许我需要用其他方式划分案件......
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
你应该考虑使用这个函数而不是viewWillAppear
伙伴。