1.先創(chuàng)建AppDelegate
2.再創(chuàng)建SceneDelegate
3.設(shè)置啟動(dòng)為AppDelegate
4.使用
效果:
這個(gè)是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
- 備注:
如果有不足或者錯(cuò)誤的地方還望各位讀者批評(píng)指正复罐,可以評(píng)論留言,筆者收到后第一時(shí)間回復(fù)撕捍。
簡(jiǎn)書(shū)號(hào):凡塵一笑:[簡(jiǎn)書(shū)]
感謝各位觀(guān)眾老爺?shù)拈喿x渠啊,如果覺(jué)得筆者寫(xiě)的還湊合迷帜,可以關(guān)注或收藏一下物舒,不定期分享一些好玩的實(shí)用的demo給大家色洞。
文/凡塵一笑(簡(jiǎn)書(shū)作者)
著作權(quán)歸作者所有戏锹,轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),并標(biāo)注“簡(jiǎn)書(shū)作者”