我正在尝试创建一个自定义UIView并使用
Swift在我的主视图中将其显示为弹出窗口.
class DatePopUpView: UIView { var uiView:UIView? override init() { super.init() self.uiView = NSBundle.mainBundle().loadNibNamed("DatePopUpView",owner: self,options: nil)[0] as? UIView } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } required override init(frame: CGRect) { super.init(frame: frame) } }
我在主视图中将其称为:
@IBAction func date_button_pressed (sender : AnyObject?) { var popUpView = DatePopUpView() var centre : CGPoint = CGPoint(x: self.view.center.x,y: self.view.center.y) popUpView.center = centre popUpView.layer.cornerRadius = 10.0 let trans = CGAffineTransformScale(popUpView.transform,0.01,0.01) popUpView.transform = trans self.view .addSubview(popUpView) UIView .animateWithDuration(0.5,delay: 0.0,options: UIViewAnimationOptions.CurveEaseInOut,animations: { popUpView.transform = CGAffineTransformScale(popUpView.transform,100.0,100.0) },completion: { (value: Bool) in }) }
但popUp并非即将到来.我使用断点并注意到该值已分配给我的popUpView但仍然没有显示在我的主视图上.请帮忙
请注意:我使用StoryBoard作为我的mainView和自定义View我使用xib.
解决方法
尝试将View修改为以下内容:
class DatePopUpView: UIView { var uiView:UIView? override init() { super.init() self.setup() } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.setup() } override init(frame: CGRect) { super.init(frame: frame) self.setup() } setup() { self.uiView = NSBundle.mainBundle().loadNibNamed("DatePopUpView",options: nil)[0] as? UIView self.uiView.frame = self.bounds self.uiView.autoresizingMask = .FlexibleWidth | .FlexibleHeight self.addSubview(self.uiView) } }