2016-02-10 68 views
0

我想創建一個動畫,其中屏幕將從中心拆分爲兩部分,以打開一個新的UIViewController如何在iOS中複製CAlayer對象?

目前,我試圖將圖層複製到兩個變量,但我無法複製該圖層。一層將向右,另一層向左,所以它看起來像打開門。

任何幫助將不勝感激。

回答

0
let ff = NSKeyedArchiver.archivedDataWithRootObject(fromViewController.view.layer) 
    let ss = NSKeyedUnarchiver.unarchiveObjectWithData(ff) as! CALayer 
    layer = ss 


    let ff1 = NSKeyedArchiver.archivedDataWithRootObject(fromViewController.view.layer) 
    let ss1 = NSKeyedUnarchiver.unarchiveObjectWithData(ff1) as! CALayer 
    layer2 = ss1 
0

可惜你不能複製的CALayer對象,UIView的實例太多,但你可以嘗試這裏的類似問題的解決方案:Can UIView be copied?

+0

我能夠爲這樣做,但有時需要時間來加載 讓利ff = NSKeyedArchiver.archivedDataWithRootObject(fromViewController.view.layer) let ss = NSKeyedUnarchiver.unarchiveObjectWithData(ff)as!的CALayer 層= SS 讓FF1 = NSKeyedArchiver.archivedDataWithRootObject(fromViewController.view.layer) 讓SS1 = NSKeyedUnarchiver.unarchiveObjectWithData(FF1)作爲! CALayer layer2 = ss1 –

+0

我該如何改進? –