实际上,我觉得这个很简单,而且我遗漏了一些东西。
我正在创建UIView的子类,而不是将其作为subView从ViewController中添加,如下所示:
rateus = RateFrameWork(AppID: "asdasds", BackGroundColor: UIColor.blueColor())
self.addSubView(rateus)我正在尝试从子类中添加它,这是我到目前为止尝试的:
class RateFrameWork: UIView 1)来自超级init编码器(剂量工作)
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)有什么建议吗?,我如何从它自己的子类中添加它作为子视图?
发布于 2015-06-02 15:15:41
你不能这样做,因为这与想法是矛盾的。
视图不具有superview,除非将其添加为子视图,而且视图不知道在什么情况下何时添加为子视图。
一些特殊的视图(例如,AlertView、ActionView)可以添加到keyWindow中,但是您的视图不能。
https://stackoverflow.com/questions/30598955
复制相似问题