我想用segue在兩個視圖之間傳遞UIImage。問題是我的UIImage在第二個視圖控制器中顯示爲白色。用segue傳遞UIImage
的賽格瑞:
var screenShot = UIImage()
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "screenshotEmbed") {
let svc = segue.destinationViewController as! screenshotViewController
svc.toPass = self.screenshot
}
的secondViewController:
class screenshotViewController: UIViewController {
@IBOutlet var screenshotView: UIImageView!
var toPass = UIImage()
override func viewDidLoad() {
super.viewDidLoad()
self.screenshotView.image = self.toPass
}
}
我的UIImage只是一個截圖,這裏的功能:
func captureScreen() -> UIImage {
var window: UIWindow? = UIApplication.sharedApplication().keyWindow
window = UIApplication.sharedApplication().windows[0]
UIGraphicsBeginImageContextWithOptions(window!.frame.size, window!.opaque, 0.0)
window!.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image;
}
編輯。上的按鈕截圖存儲:
@IBAction func photoAction(sender: AnyObject) {
self.screenShot = captureScreen()
}
我試過很多的事情,但還是空白(非空事業內存ADRESS是好的)。
screenshotImage是一個河畔的UIImage。這很奇怪。如果我做svc.toPass = capture()它也可以..但我必須在screenshotImage上存儲。我將使用screenshoteImage存儲編輯帖子 – Makaille
您的'screenshotImage'對象具有任何圖像? –
不錯,這是我的IBAction(我存儲screenShot)的問題是在AnyObject上,而不是在UIbutton上。我認爲它仍然很奇怪,但現在它的工作... – Makaille