ios – 创建自定义UIView并在Swift中显示为Pop Up

我正在尝试创建一个自定义UIView并使用 Swift在我的主视图中将其显示为弹出窗口.

我的自定义UIView代码

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)
     }
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...