|
@@ -13,7 +13,7 @@ import UIKit
|
|
|
|
|
|
/// UIView的分类扩展
|
|
|
extension UIView {
|
|
|
- public func addCorner(roundingCorners: UIRectCorner = .allCorners, corner: CGFloat = cDefaultMargin) {
|
|
|
+ public func addCorner(roundingCorners: UIRectCorner = .allCorners, corner: CGFloat = cDefaultMargin) {
|
|
|
if roundingCorners == .allCorners {
|
|
|
layer.cornerRadius = corner
|
|
|
layer.masksToBounds = true
|
|
@@ -31,7 +31,7 @@ extension UIView {
|
|
|
/// - color: <#color description#>
|
|
|
/// - offset: <#offset description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func addShadowLayer(isAll: Bool = false, color: UIColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5), offset: CGSize = CGSize(width: 1, height: 1)) {
|
|
|
+ public func addShadowLayer(isAll: Bool = false, color: UIColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5), offset: CGSize = CGSize(width: 1, height: 1)) {
|
|
|
layer.shadowColor = color.cgColor
|
|
|
layer.shadowOffset = offset
|
|
|
layer.shadowRadius = 0.5
|
|
@@ -48,7 +48,7 @@ extension UIView {
|
|
|
}
|
|
|
|
|
|
/// 添加虚线条
|
|
|
- func addBorderToLayer(frame: CGRect? = nil) {
|
|
|
+ public func addBorderToLayer(frame: CGRect? = nil) {
|
|
|
// 线条颜色
|
|
|
let borderLayer: CAShapeLayer = CAShapeLayer()
|
|
|
borderLayer.strokeColor = UIColor.hexColor(hexadecimal: "#FFFFFF").cgColor
|
|
@@ -62,7 +62,7 @@ extension UIView {
|
|
|
layer.addSublayer(borderLayer)
|
|
|
}
|
|
|
|
|
|
- func animateZoom() {
|
|
|
+ public func animateZoom() {
|
|
|
transform = CGAffineTransform(scaleX: 0.4, y: 0.4)
|
|
|
UIView.animate(withDuration: 0.5, animations: {
|
|
|
self.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
|
|
@@ -81,7 +81,7 @@ extension UIView {
|
|
|
/// - duration: <#duration description#>
|
|
|
/// - repeatCount: <#repeatCount description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func shakeAnimation(_ fromValue: Float, _ toValue: Float, _ duration: Float, _: Float) {
|
|
|
+ public func shakeAnimation(_ fromValue: Float, _ toValue: Float, _ duration: Float, _: Float) {
|
|
|
layer.removeAllAnimations()
|
|
|
let shake = CABasicAnimation(keyPath: "transform.rotation.z")
|
|
|
shake.fromValue = fromValue
|
|
@@ -101,7 +101,7 @@ extension UIView {
|
|
|
/// - isRepeat: <#isRepeat description#>
|
|
|
/// - multiple: <#multiple description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func heartbeatAnimate(duration: TimeInterval, isRepeat: Bool, multiple: CGFloat) {
|
|
|
+ public func heartbeatAnimate(duration: TimeInterval, isRepeat: Bool, multiple: CGFloat) {
|
|
|
UIView.animateKeyframes(withDuration: duration, delay: 0, options: .allowUserInteraction, animations: {
|
|
|
self.transform = CGAffineTransform(scaleX: 1.0 + multiple, y: 1.0 + multiple)
|
|
|
}) { _ in
|
|
@@ -127,7 +127,7 @@ extension UIView {
|
|
|
|
|
|
/// 活动心跳动画
|
|
|
/// - Returns: <#description#>
|
|
|
- func activityHeartbeatAnimate() {
|
|
|
+ public func activityHeartbeatAnimate() {
|
|
|
layer.removeAllAnimations()
|
|
|
UIView.animateKeyframes(withDuration: 0.45, delay: 0, options: .allowUserInteraction, animations: {
|
|
|
self.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
|
@@ -142,7 +142,7 @@ extension UIView {
|
|
|
|
|
|
/// 活动心跳动画
|
|
|
/// - Returns: <#description#>
|
|
|
- func heartbeatAnimate() {
|
|
|
+ public func heartbeatAnimate() {
|
|
|
layer.removeAllAnimations()
|
|
|
UIView.animateKeyframes(withDuration: 1, delay: 0, options: .allowUserInteraction, animations: {
|
|
|
self.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
|
|
@@ -157,7 +157,7 @@ extension UIView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func addScaleBasicAnimation() {
|
|
|
+ public func addScaleBasicAnimation() {
|
|
|
let animation = CABasicAnimation(keyPath: "transform.scale")
|
|
|
animation.timingFunction = CAMediaTimingFunction(name: .easeOut)
|
|
|
animation.duration = 0.5
|
|
@@ -168,7 +168,7 @@ extension UIView {
|
|
|
layer.add(animation, forKey: nil)
|
|
|
}
|
|
|
|
|
|
- func addScaleYBasicAnimation() {
|
|
|
+ public func addScaleYBasicAnimation() {
|
|
|
let animation = CAKeyframeAnimation(keyPath: "transform.translation.y")
|
|
|
animation.duration = 0.5
|
|
|
animation.repeatCount = 100
|
|
@@ -191,7 +191,7 @@ extension UIView {
|
|
|
|
|
|
/// 将view生成一张图片
|
|
|
/// - Returns: <#description#>
|
|
|
- func graphicsGetImage() -> UIImage? {
|
|
|
+ public func graphicsGetImage() -> UIImage? {
|
|
|
UIGraphicsBeginImageContextWithOptions(frame.size, true, 0.0)
|
|
|
layer.render(in: UIGraphicsGetCurrentContext()!)
|
|
|
let newImage = UIGraphicsGetImageFromCurrentImageContext()
|
|
@@ -201,7 +201,7 @@ extension UIView {
|
|
|
|
|
|
/// 动画显示View
|
|
|
/// - Returns: <#description#>
|
|
|
- func showViewAnimate(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
|
|
|
+ public func showViewAnimate(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
|
|
|
UIView.animate(withDuration: duration, animations: { [weak self] in
|
|
|
self?.frame = CGRect(x: 0, y: cScreenHeigth - self!.frame.height, width: self!.frame.width, height: self!.frame.height)
|
|
|
}) { isFinished in
|
|
@@ -213,7 +213,7 @@ extension UIView {
|
|
|
|
|
|
/// 动画隐藏view
|
|
|
/// - Returns: <#description#>
|
|
|
- func dismissViewAnimate(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
|
|
|
+ public func dismissViewAnimate(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
|
|
|
UIView.animate(withDuration: duration, animations: { [weak self] in
|
|
|
self?.frame = CGRect(x: 0, y: cScreenHeigth, width: self!.frame.width, height: self!.frame.height)
|
|
|
}) { isFinished in
|
|
@@ -226,7 +226,7 @@ extension UIView {
|
|
|
/// add by ak 添加虚线框
|
|
|
/// - Parameter color: 框色
|
|
|
/// - Parameter lineWidth: 框宽
|
|
|
- func addBorderToLayer(color: CGColor, lineWidth: CGFloat) {
|
|
|
+ public func addBorderToLayer(color: CGColor, lineWidth: CGFloat) {
|
|
|
let border = CAShapeLayer()
|
|
|
|
|
|
// 线条颜色
|
|
@@ -251,7 +251,7 @@ extension UIView {
|
|
|
extension UICollectionView {
|
|
|
/// 获取当前cell
|
|
|
/// - Returns: <#description#>
|
|
|
- func visibleCell() -> UICollectionViewCell? {
|
|
|
+ public func visibleCell() -> UICollectionViewCell? {
|
|
|
let visibleRect = CGRect(origin: contentOffset, size: bounds.size)
|
|
|
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
|
|
|
guard let visibleIndexPath = indexPathForItem(at: visiblePoint) else { return nil }
|
|
@@ -262,7 +262,7 @@ extension UICollectionView {
|
|
|
/// - Parameters:
|
|
|
/// - scroller: <#scroller description#>
|
|
|
/// - type: 1-头部跟尾部 2-头部 3-尾部
|
|
|
- func addRefreshView(type: REFRESH_TYPE = .REFRESH_TYPE_ALL, refreshHandle: ((_ isHeader: Bool) -> Void)?) {
|
|
|
+ public func addRefreshView(type: REFRESH_TYPE = .REFRESH_TYPE_ALL, refreshHandle: ((_ isHeader: Bool) -> Void)?) {
|
|
|
if type == .REFRESH_TYPE_ALL || type == .REFRESH_TYPE_HEADER {
|
|
|
let header = MJRefreshNormalHeader.init {
|
|
|
if refreshHandle != nil {
|
|
@@ -290,7 +290,7 @@ extension UICollectionView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func indexPathsForElements(in rect: CGRect) -> [IndexPath] {
|
|
|
+ public func indexPathsForElements(in rect: CGRect) -> [IndexPath] {
|
|
|
let allLayoutAttributes = collectionViewLayout.layoutAttributesForElements(in: rect)!
|
|
|
return allLayoutAttributes.map { $0.indexPath }
|
|
|
}
|
|
@@ -303,7 +303,7 @@ extension UITabBar {
|
|
|
/// 展示小红点
|
|
|
/// - Parameter index: <#index description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func showPoint(index: Int) {
|
|
|
+ public func showPoint(index: Int) {
|
|
|
let pointW: CGFloat = 8
|
|
|
let pointView = UIView()
|
|
|
pointView.tag = 11111 + index
|
|
@@ -319,7 +319,7 @@ extension UITabBar {
|
|
|
/// 移除小红点
|
|
|
/// - Parameter index: <#index description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func removePoint(index: Int) {
|
|
|
+ public func removePoint(index: Int) {
|
|
|
for item in subviews {
|
|
|
if item.tag == 11111 + index {
|
|
|
item.removeFromSuperview()
|
|
@@ -330,7 +330,7 @@ extension UITabBar {
|
|
|
/// 展示创作视频引导
|
|
|
/// - Parameter index: <#index description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func showVideoMakeRemindView() {
|
|
|
+ public func showVideoMakeRemindView() {
|
|
|
let isOldUploadClick: String? = getUserDefaults(key: cIsUploadClick) as? String
|
|
|
let isUploadClick: String? = getUserDefaultsForJson(key: cIsUploadClick) as? String
|
|
|
let isVerticalSlip: String? = getUserDefaults(key: cIsVerticalSlip) as? String
|
|
@@ -355,13 +355,13 @@ extension UITabBar {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @objc func dismiss() {
|
|
|
+ @objc public func dismiss() {
|
|
|
|
|
|
}
|
|
|
|
|
|
/// 移除创作视频引导
|
|
|
/// - Returns: <#description#>
|
|
|
- func removeVideoMakeRemindView() {
|
|
|
+ public func removeVideoMakeRemindView() {
|
|
|
viewWithTag(cVideoMakeRemindTag)?.removeFromSuperview()
|
|
|
}
|
|
|
}
|
|
@@ -399,7 +399,7 @@ extension UILabel {
|
|
|
/// - color: <#color description#>
|
|
|
/// - offset: <#offset description#>
|
|
|
/// - Returns: <#description#>
|
|
|
- func addShadow(color: UIColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5), offset: CGSize = CGSize(width: 1, height: 1)) {
|
|
|
+ public func addShadow(color: UIColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5), offset: CGSize = CGSize(width: 1, height: 1)) {
|
|
|
shadowColor = color
|
|
|
shadowOffset = offset
|
|
|
}
|
|
@@ -409,7 +409,7 @@ extension UIImageView {
|
|
|
/// imageView加载网络图片
|
|
|
/// - Parameters:
|
|
|
/// - url: 网络url
|
|
|
- func setNetImage(url: String?, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
+ public func setNetImage(url: String?, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
if url == nil || (url?.count ?? 0) <= 0 {
|
|
|
BFLog(message: "设置按钮网络图片地址为空")
|
|
|
return
|
|
@@ -422,7 +422,7 @@ extension UIImageView {
|
|
|
|
|
|
/// 展示加载中动画
|
|
|
/// - Returns: <#description#>
|
|
|
- func showLoadingAnimation(duration: Double = 1) {
|
|
|
+ public func showLoadingAnimation(duration: Double = 1) {
|
|
|
let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
|
|
|
rotationAnim.fromValue = 0
|
|
|
rotationAnim.toValue = Double.pi * 2
|
|
@@ -439,7 +439,7 @@ extension UIImageView {
|
|
|
/// - repeatCount: 循环次数
|
|
|
/// - duration: 时长
|
|
|
/// - Returns: <#description#>
|
|
|
- func displayGIF(data: Data? = nil, images: [UIImage]? = nil, repeatCount: Int = Int.max, duration: Double = 1) {
|
|
|
+ public func displayGIF(data: Data? = nil, images: [UIImage]? = nil, repeatCount: Int = Int.max, duration: Double = 1) {
|
|
|
if images != nil, (images?.count ?? 0) > 0, !isAnimating {
|
|
|
layer.removeAllAnimations()
|
|
|
stopAnimating()
|
|
@@ -461,7 +461,7 @@ extension UIButton {
|
|
|
/// UIButton加载网络图片
|
|
|
/// - Parameters:
|
|
|
/// - url: 网络url
|
|
|
- func setNetImage(url: String?, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
+ public func setNetImage(url: String?, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
if url == nil || (url?.count ?? 0) <= 0 {
|
|
|
BFLog(message: "设置按钮网络图片地址为空")
|
|
|
return
|
|
@@ -475,7 +475,7 @@ extension UIButton {
|
|
|
/// UIButton加载网络背景图片
|
|
|
/// - Parameters:
|
|
|
/// - url: 网络url
|
|
|
- func setNetBackgroundImage(url: String, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
+ public func setNetBackgroundImage(url: String, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
// kf.setBackgroundImage(with: URL(string: url), for: .normal, placeholder: placeholder, options: url.suffix(5) == ".webp" ? [.processor(WebPProcessor.default), .cacheSerializer(WebPSerializer.default)] : nil, progressBlock: { _, _ in
|
|
|
//
|
|
|
// }) { _, _, _, _ in
|