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 0000000..ece3352 Binary files /dev/null and b/EBBannerView/SwiftClasses/EBMuteDetector.mp3 differ diff --git a/EBBannerView/SwiftClasses/EBSystemBanner.swift b/EBBannerView/SwiftClasses/EBSystemBanner.swift index aa1e0c1..dd6033c 100644 --- a/EBBannerView/SwiftClasses/EBSystemBanner.swift +++ b/EBBannerView/SwiftClasses/EBSystemBanner.swift @@ -76,7 +76,13 @@ public class EBSystemBanner: NSObject { /// .onClick { /// print($0.object!) /// } - public func object(_ object: Any?) -> 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..c1d67bf 100644 --- a/EBBannerView/SwiftClasses/EBSystemBannerView.swift +++ b/EBBannerView/SwiftClasses/EBSystemBannerView.swift @@ -28,10 +28,6 @@ class EBSystemBannerView: UIView { return super.hitTest(point, with: event) } } - - - - } @@ -58,7 +54,7 @@ extension EBSystemBannerView { 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 + let calculatedHeight = str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [.font : contentLabel.font], context: nil).size.height //20 return calculatedHeight } @@ -112,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) { @@ -126,6 +128,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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +