在项目中,有的时候需要用到一些特殊的弹窗,并在弹窗上添加一些自定义的功能,这个时候我们就需要自定义弹窗了!
带xib的弹窗文件
调用弹窗的方法:
class func show(view: UIView?) -> AlertView {
var supperView: UIView!
if view == nil {
let delegate = UIApplication.shared.delegate as! AppDelegate
supperView = delegate.window
} else {
supperView = view
}
let nib = UINib(nibName: "AlertView", bundle: Bundle(for: AlertView.self))
let alertView = nib.instantiate(withOwner: nil, options: nil)[0] as! FriendAddAlertView
supperView.addSubview(alertView)
alertView.frame = CGRect(x: 0, y: 0, width: AppConfig.screenWidth, height: AppConfig.screenHeight)
alertView.alpha = 0
UIView.animate(withDuration: 0.2) {
alertView.alpha = 1
}
return alertView
}
如果需要在弹窗上进行一些操作,则声明添加并在某个时机发送block:
typealias addFriendBlock = (_ select: Bool) -> Void
var selectBlock: addFriendBlock?
if selectBlock != nil {
selectBlock!(true)
}