【发布时间】:2015-03-23 06:05:02
【问题描述】:
我正在尝试创建一个自定义 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 和我使用 xib 制作的自定义视图。
【问题讨论】:
-
你确定你的 date_button_pressed() 函数被调用了吗?
-
好的,现在我怀疑你的观点了。
-
你为什么不临时创建一个单独的项目。在主 vc 中加载你的 nib,看看你是否可以看到和调整你的视图。如果它看起来不错,那么我们可以重新审视这种情况
-
我尝试提供框架并添加
var popUpView = DatePopUpView() popUpView.frame = CGRectMake(40, 40, 200, 200) self.view .addSubview(popUpView)但没有成功