1.先创建AppDelegate
2.再创建SceneDelegate
3.设置启动为AppDelegate
4.使用
效果:
这个是swift的View里面的代码,
import UIKit
import SnapKit
private let DateView_H = 590
class testLoacationView: UIView {
lazy private var dateView : UIView = {
let dateView = UIView()
dateView.backgroundColor = UIColor.white
dateView.layer.masksToBounds = true
dateView.layer.cornerRadius = 15
return dateView
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.frame = UIScreen.main.bounds
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension testLoacationView {
func setupUI() {
let bgView = UIImageView()
bgView.frame = UIScreen.main.bounds
bgView.alpha = 0.6
bgView.backgroundColor = .black
addSubview(bgView)
bgView.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(hidden))
bgView.addGestureRecognizer(tap)
addSubview(dateView)
dateView.snp.makeConstraints { make in
make.height.equalTo(DateView_H);
make.left.equalToSuperview();
make.right.equalToSuperview();
make.bottom.equalToSuperview().offset(10);
}
}
}
extension testLoacationView{
func show() {
//let keyWindow = keyWindow
keyWindow?.addSubview(self)
dateView.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: CGFloat(DateView_H))
UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut) {
self.dateView.frame = CGRect(x: 0, y: UIScreen.main.bounds.height - CGFloat(DateView_H), width: UIScreen.main.bounds.width, height: CGFloat(DateView_H))
} completion: { _ in
}
}
@objc func hidden() {
UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut) {
self.dateView.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: CGFloat(DateView_H))
} completion: { _ in
self.removeFromSuperview()
}
}
}
代码留给你
https://gitee.com/lanyingwei/codes/z8i9jqys5uabgvmcfn0ep34
- 备注:
如果有不足或者错误的地方还望各位读者批评指正,可以评论留言,笔者收到后第一时间回复。
简书号:凡尘一笑:[简书]
感谢各位观众老爷的阅读,如果觉得笔者写的还凑合,可以关注或收藏一下,不定期分享一些好玩的实用的demo给大家。
文/凡尘一笑(简书作者)
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”