取消PopupWindow比较简单,将view从其容器中移除,并将其强引用置空。为了实现从底部消失的效果,仍然用UIView动画变换y坐标实现。
func cancel() {
UIView.animate(withDuration: 0.3) {
animation in
self.view.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
self.view.removeFromSuperview()
}
strongSelf = nil
}
调用
在调用类中实现PopupWindowDelegate协议,重写交互函数。创建PopupWindow对象,并设置委托属性和其他属性。
let popupWindow = UIStoryboard(name: "DefiniteUI", bundle: nil).instantiateViewController(withIdentifier: "popup") as! PopupWindow
popupWindow.delegate = self
popupWindow.create().setItems(value: items)
效果
弹出PopWindow:

取消PopWindow:

后记
举一反三,除了PopupWindow,类似的各种自定义的Dialog都可以这样去实现,读者可以去试试。以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。
注:相关教程知识阅读请移步到IOS开发频道。










