From dc6538e735a98cb1e60a687f76a7661b7ed122a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0?= <512330546@qq.com> Date: Tue, 7 Apr 2020 15:12:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20swift=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwiftClasses/EBBannerViewController.xib | 23 + EBBannerView/SwiftClasses/EBMuteDetector.mp3 | Bin 0 -> 1706 bytes .../SwiftClasses/EBSystemBanner.swift | 26 +- .../SwiftClasses/EBSystemBannerMaker.swift | 3 +- .../SwiftClasses/EBSystemBannerView.swift | 10 +- .../SwiftClasses/EBSystemBannerView.xib | 591 ++++++++++++++++++ 6 files changed, 641 insertions(+), 12 deletions(-) create mode 100644 EBBannerView/SwiftClasses/EBBannerViewController.xib create mode 100755 EBBannerView/SwiftClasses/EBMuteDetector.mp3 create mode 100644 EBBannerView/SwiftClasses/EBSystemBannerView.xib diff --git a/EBBannerView/SwiftClasses/EBBannerViewController.xib b/EBBannerView/SwiftClasses/EBBannerViewController.xib new file mode 100644 index 0000000..96877a1 --- /dev/null +++ b/EBBannerView/SwiftClasses/EBBannerViewController.xib @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EBBannerView/SwiftClasses/EBMuteDetector.mp3 b/EBBannerView/SwiftClasses/EBMuteDetector.mp3 new file mode 100755 index 0000000000000000000000000000000000000000..ece3352dbb507dcbb573301daf473358852c0201 GIT binary patch literal 1706 zcmds%`B&0e7{>1xP|(E4T}nZ7J0*&UTcZU9rb%jwrPi3Zw73t6X-?u+?osNHEtHfU z&8((vN;~G7tx6W9X_F{AX0~AF=(v67Tb(n1#60)hbDsOT?|aWZ&kwIR%MlF_L1ZqI zvmP<_h=&(FfdKH4y$|p}GDrku5CEb<1mgH00Xc=i0%{R8h`NUw26O${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E8rf97KyPxUjq`}A{nut-e*pmhTUU54mv zfWiDxA6?oXb*!Ub3rnvFMch!XyPn~ykMOqBC@-<$0_wE%l4T498 z;0wbABNNV!pL{#G0tcXQjj5*e+4+~XeoQMP8%tTD@07I*-%n|4>MC45V0Yb8F_f=) z@vLHoj9!{ef}y-N@KY@y*y!OfXsEfFVM74qmfecnZ~1Fvq9Q$>exfVDmfiK2J8F EBSystemBanner { return then { $0.maker.object = object } } + public func object(_ object: Any?) -> EBSystemBanner { + return then { + $0.maker.object = object +// NotificationCenter.default.addObserver(self, selector: #selector(onClick(_:)), name: EBSystemBanner.onClickNotification, object: nil) + } + + } /// Play a sound when a banner appears /// @@ -100,7 +106,11 @@ public class EBSystemBanner: NSObject { public func showDetailsOrHideWhenClickLongText(_ bool: Bool) -> EBSystemBanner { return then { $0.maker.showDetailsOrHideWhenClickLongText = bool } } @discardableResult - public func onClick(_ block: @escaping (EBSystemBanner) -> ()) -> EBSystemBanner { return then { $0.maker.onClick = block } } + @objc public func onClick(_ block: @escaping (EBSystemBanner) -> ()) -> EBSystemBanner { + return then { + $0.maker.onClick = block + } + } @discardableResult @@ -136,7 +146,9 @@ public class EBSystemBanner: NSObject { EBSystemBanner.sharedBannerViews.append(view) bannerView = view } + maker.banner = self bannerView?.maker = maker + if style == .iOS9 { bannerView?.dateLabel.textColor = UIColor.color(at: bannerView!.dateLabel.center).withAlphaComponent(0.7) let lineCenter = bannerView!.lineView.center @@ -189,14 +201,20 @@ extension EBSystemBanner { public var sound: EBBannerSound { return maker.sound } public var vibrateOnMute: Bool { return maker.vibrateOnMute } public var showDetailsOrHideWhenClickLongText: Bool { return maker.showDetailsOrHideWhenClickLongText } - public var onClick: (EBSystemBanner) -> () { return maker.onClick } + public var onClick: (EBSystemBanner) -> () { return maker.onClick } } //偷偷写个then,没人看到我 没人看到我🙈 protocol EBThen {} extension EBThen where Self: AnyObject { func then(_ block: (Self) throws -> Void) rethrows -> Self { - try block(self) +// try block(self) + do { + try block(self) + } catch { + print("错误///") + } + return self } } diff --git a/EBBannerView/SwiftClasses/EBSystemBannerMaker.swift b/EBBannerView/SwiftClasses/EBSystemBannerMaker.swift index 12b7fc1..ffb99cb 100644 --- a/EBBannerView/SwiftClasses/EBSystemBannerMaker.swift +++ b/EBBannerView/SwiftClasses/EBSystemBannerMaker.swift @@ -63,5 +63,6 @@ class EBSystemBannerMaker: NSObject { var showDetailsOrHideWhenClickLongText = true var onClick = { (view: EBSystemBanner) in } - + + var banner: EBSystemBanner! } diff --git a/EBBannerView/SwiftClasses/EBSystemBannerView.swift b/EBBannerView/SwiftClasses/EBSystemBannerView.swift index 3bac16d..fca7ddd 100644 --- a/EBBannerView/SwiftClasses/EBSystemBannerView.swift +++ b/EBBannerView/SwiftClasses/EBSystemBannerView.swift @@ -28,10 +28,6 @@ class EBSystemBannerView: UIView { return super.hitTest(point, with: event) } } - - - - } @@ -57,9 +53,8 @@ extension EBSystemBannerView { var calculatedContentHeight: CGFloat { let size = CGSize(width: contentLabel.frame.size.width, height: CGFloat.greatestFiniteMagnitude) let text = contentLabel.text ?? "" - let str = text as NSString - let calculatedHeight = str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [.font : contentLabel.font.pointSize], context: nil).size.height - return calculatedHeight + let calculatedHeight = 20//text.stringHeightWith(fontSize: contentLabel?.font.pointSize ?? 14, width: size.width, lineSpace: 2)//20//str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [.font : contentLabel.font.pointSize], context: nil).size.height //20 + return CGFloat(calculatedHeight) } var isPortrait: Bool { return UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height } @@ -126,6 +121,7 @@ extension EBSystemBannerView { swipeDownSelector(ges: ges) } else { NotificationCenter.default.post(name: EBSystemBanner.onClickNotification, object: maker.object) + maker.onClick(maker.banner) hide() } } diff --git a/EBBannerView/SwiftClasses/EBSystemBannerView.xib b/EBBannerView/SwiftClasses/EBSystemBannerView.xib new file mode 100644 index 0000000..4e6492f --- /dev/null +++ b/EBBannerView/SwiftClasses/EBSystemBannerView.xib @@ -0,0 +1,591 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From e67a23beb74455970bab1058c46be6727b90c025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0?= <512330546@qq.com> Date: Tue, 7 Apr 2020 15:49:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9iOS13=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E9=97=AA=E5=B1=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwiftClasses/EBSystemBannerView.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/EBBannerView/SwiftClasses/EBSystemBannerView.swift b/EBBannerView/SwiftClasses/EBSystemBannerView.swift index fca7ddd..c1d67bf 100644 --- a/EBBannerView/SwiftClasses/EBSystemBannerView.swift +++ b/EBBannerView/SwiftClasses/EBSystemBannerView.swift @@ -53,8 +53,9 @@ extension EBSystemBannerView { var calculatedContentHeight: CGFloat { let size = CGSize(width: contentLabel.frame.size.width, height: CGFloat.greatestFiniteMagnitude) let text = contentLabel.text ?? "" - let calculatedHeight = 20//text.stringHeightWith(fontSize: contentLabel?.font.pointSize ?? 14, width: size.width, lineSpace: 2)//20//str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [.font : contentLabel.font.pointSize], context: nil).size.height //20 - return CGFloat(calculatedHeight) + let str = text as NSString + let calculatedHeight = str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [.font : contentLabel.font], context: nil).size.height //20 + return calculatedHeight } var isPortrait: Bool { return UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height } @@ -107,11 +108,17 @@ extension EBSystemBannerView { hideTimer = nil hideTimer = Timer.scheduledTimer(timeInterval: maker.spreadStayDuration, target: self, selector: #selector(hide), userInfo: nil, repeats: false) let originContentHeight = contentLabel.frame.size.height - UIView.animate(withDuration: maker.hideDuration, delay: 0, usingSpringWithDamping: EBSystemBannerView.damping, initialSpringVelocity: 0, options: .curveEaseInOut, animations: { - self.frame = CGRect(x: self.fixedX, y: self.fixedY, width: self.standardHeight, height: self.calculatedContentHeight - originContentHeight + 1) - }) { (finish) in + + + UIView.animate(withDuration: 0.1) { self.frame = CGRect(x: self.fixedX, y: self.fixedY, width: self.fixedWidth, height: self.standardHeight + self.calculatedContentHeight - originContentHeight + 1) } + +// UIView.animate(withDuration: maker.hideDuration, delay: 0, usingSpringWithDamping: EBSystemBannerView.damping, initialSpringVelocity: 0, options: .curveEaseInOut, animations: { +// self.frame = CGRect(x: self.fixedX, y: self.fixedY, width: self.standardHeight, height: self.calculatedContentHeight - originContentHeight + 1) +// }) { (finish) in +// self.frame = CGRect(x: self.fixedX, y: self.fixedY, width: self.fixedWidth, height: self.standardHeight + self.calculatedContentHeight - originContentHeight + 1) +// } } @objc func tapSelector(ges: UISwipeGestureRecognizer) {