0

其实我认为这个很简单,我错过了一些东西。

我正在创建 UIView 的子类,而不是像这样从 ViewController 将其添加为子视图:

rateus = RateFrameWork(AppID: "asdasds", BackGroundColor: UIColor.blueColor())
self.addSubView(rateus)

我正在尝试从子类中添加它,这是我到目前为止所尝试的:

class RateFrameWork: UIView 

1)来自超级初始化编码器(剂量工作)

 required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        superview?.addSubview(self)

    }

2)从init方法(剂量工作)

init?(AppID: String!, BackGroundColor: UIColor!)
super.init(frame: CGRect(x:  0 , y: 0, width: UIScreen.mainScreen().bounds.size.width , height:UIScreen.mainScreen().bounds.size.height))
 superview?.addSubview(self)

有什么建议么?如何将其添加为来自其自己的子类的子视图?

4

1 回答 1

2

你不能这样做,因为这与这个想法相矛盾。

除非要添加为子视图,否则视图没有超级视图,并且视图不知道在什么情况下以及何时将其添加为子视图。

一些特殊视图(例如 AlertView、ActionView)可以添加到keyWindow您的视图中,但不能。

于 2015-06-02T15:15:41.443 回答