Can UIView be copied?

后端 未结 6 1611
广开言路
广开言路 2020-11-27 15:02

Simply using this way:

UIView* view2 = [view1 copy]; // view1 existed

This will cause simulator can not launch this app.

Try retai

6条回答
  •  盖世英雄少女心
    2020-11-27 15:43

    for swift3.0.1:

    extension UIView{
     func copyView() -> AnyObject{
        return NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: self))! as AnyObject
     }
    }
    

提交回复
热议问题