Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions EBBannerView/SwiftClasses/EBBannerViewController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14269.12" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14252.5"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="EBBannerViewController">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</objects>
</document>
Binary file added EBBannerView/SwiftClasses/EBMuteDetector.mp3
Binary file not shown.
26 changes: 22 additions & 4 deletions EBBannerView/SwiftClasses/EBSystemBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
3 changes: 2 additions & 1 deletion EBBannerView/SwiftClasses/EBSystemBannerMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ class EBSystemBannerMaker: NSObject {
var showDetailsOrHideWhenClickLongText = true

var onClick = { (view: EBSystemBanner) in }


var banner: EBSystemBanner!
}
19 changes: 11 additions & 8 deletions EBBannerView/SwiftClasses/EBSystemBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class EBSystemBannerView: UIView {
return super.hitTest(point, with: event)
}
}





}

Expand All @@ -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
}

Expand Down Expand Up @@ -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) {
Expand All @@ -126,6 +128,7 @@ extension EBSystemBannerView {
swipeDownSelector(ges: ges)
} else {
NotificationCenter.default.post(name: EBSystemBanner.onClickNotification, object: maker.object)
maker.onClick(maker.banner)
hide()
}
}
Expand Down
Loading