Skip to content

Commit

Permalink
update Utils&View Code
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsfliu committed Jul 25, 2024
1 parent 98da92f commit 8e2505b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
4 changes: 2 additions & 2 deletions RTCCommon.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "RTCCommon"
spec.version = "1.0.2"
spec.version = "1.0.3"
spec.platform = :ios
spec.ios.deployment_target = '12.0'
spec.license = { :type => 'Proprietary',
Expand All @@ -15,7 +15,7 @@ Pod::Spec.new do |spec|
spec.summary = 'RTCCommon'
spec.swift_version = '5.0'

spec.source = { :git => 'https://github.com/Tencent-RTC/uikit-common.git', :tag => 'v1.0.2' }
spec.source = { :git => 'https://github.com/Tencent-RTC/uikit-common.git', :tag => 'v1.0.3' }
spec.source_files = 'Source/**/**/*.*', 'Source/Utils/**/*.*'

spec.dependency 'SnapKit'
Expand Down
18 changes: 5 additions & 13 deletions Source/Utils/AlertTransitionAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@

import Foundation

// 转场管理器
class AlertTransitionAnimator: NSObject {
enum AlertTransitionStyle {
// 弹出
case present
// 消失
case dismiss
}

enum AlertTransitionPosition {
// 弹出的位置
case bottom
case right
case center
}

var duration = 0.5
var alertTransitionStyle: AlertTransitionStyle = .present // 动画的类型
var alertTransitionPosition: AlertTransitionPosition = .bottom // 动画弹出的位置
var alertTransitionStyle: AlertTransitionStyle = .present
var alertTransitionPosition: AlertTransitionPosition = .bottom
deinit {
debugPrint("deinit \(self)")
}
Expand All @@ -39,9 +35,8 @@ extension AlertTransitionAnimator {
let contentView = transitionContext.containerView
fromView.tintAdjustmentMode = .normal
fromView.isUserInteractionEnabled = false
toView.isUserInteractionEnabled = false // 禁止页面产生用户交互
contentView.addSubview(toView) // 添加目标视图
// 根据弹出的位置计算动画开始前toview的frame
toView.isUserInteractionEnabled = false
contentView.addSubview(toView)
switch alertTransitionPosition {
case .bottom:
toView.frame = CGRect(x: 0, y: contentView.bounds.size.height, width: contentView.bounds.size.width, height:
Expand All @@ -66,7 +61,6 @@ extension AlertTransitionAnimator {
toView.alpha = 1
}
}) { _ in
// 动画结束后恢复两个页面的用户交互能力
fromView.isUserInteractionEnabled = true
toView.isUserInteractionEnabled = true
transitionContext.completeTransition(true)
Expand All @@ -78,9 +72,8 @@ extension AlertTransitionAnimator {
else { return }
guard let fromView = fromController.view, let toView = toController.view else { return }
fromView.isUserInteractionEnabled = false
toView.isUserInteractionEnabled = false // 禁止两个页面产生用户交互
toView.isUserInteractionEnabled = false
let contentView = transitionContext.containerView
// 根据弹出的位置计算动画开始前toview的frame
UIView.animate(withDuration: duration, animations: { [weak self] in
guard let self = self else { return }
switch self.alertTransitionPosition {
Expand All @@ -97,7 +90,6 @@ extension AlertTransitionAnimator {
}
}) { _ in
fromView.removeFromSuperview()
// 动画结束后恢复页面的用户交互能力
toView.isUserInteractionEnabled = true
transitionContext.completeTransition(true)
}
Expand Down
10 changes: 4 additions & 6 deletions Source/Utils/ApplicationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by xcoderliu on 12/24/19.
// Copyright © 2022 Tencent. All rights reserved.
//
// 用于TRTC_SceneDemo

import UIKit

Expand All @@ -27,32 +26,31 @@ extension ApplicationUtils {
return Bundle.main
}

/// app名称
public static var displayName: String {
guard let name = applicationBundle.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String else {
return ""
}
return name
}
/// App版本,带构建版本

public static var appVersionWithBuild: String {
return "\(appVersion).\(buildNumber)"
}
/// App版本号 eg. 9.4.0

public static var appVersion: String {
guard let version = applicationBundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else {
return ""
}
return version
}
/// App构建版本号 eg. 10765

public static var buildNumber: String {
guard let number = applicationBundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String else {
return ""
}
return number
}
/// App主版本号 eg. 9

public static var majorAppVersion: String {
return appVersion.components(separatedBy: ".").first ?? ""
}
Expand Down
9 changes: 0 additions & 9 deletions Source/Utils/Observers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class Observable<Type> {
}
}

// MARK: - Properties 利用Swift 的didSet 特性把值回调给callback
public var value: Type {
didSet {
removeNilObserverCallbacks()
Expand All @@ -39,7 +38,6 @@ public class Observable<Type> {
callbacks = callbacks.filter { $0.observer != nil }
}

// MARK: 回调给callback 实现闭包回调
private func notifyCallbacks(value: Type, option: ObservableOptions) {
let callbacksToNotify = callbacks.filter { $0.options.contains(option) }
callbacksToNotify.forEach { $0.closure(value, option) }
Expand All @@ -53,13 +51,6 @@ public class Observable<Type> {
// MARK: - Managing Observers
private var callbacks: [Callback] = []

/// 添加观察者
///
/// - Parameters:
/// - observer: 观察者
/// - removeIfExists: 如果观察者存在需要移除
/// - options: 被观察者
/// - closure: 回调
public func addObserver(
_ observer: AnyObject,
removeIfExists: Bool = true,
Expand Down
2 changes: 1 addition & 1 deletion Source/Utils/WindowUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// WindowUtils.swift
// RTCCommon
//
// Created by krab on 2023/10/16.
// Created by krabyu on 2023/10/16.
//

import Foundation
Expand Down
40 changes: 38 additions & 2 deletions Source/View/PopupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ import SnapKit
import UIKit

public class PopupViewController: UIViewController {

private let contentView: UIView
public init(contentView: UIView) {
private let supportBlurView: Bool

private let blurEffectView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .dark)
let view = UIVisualEffectView(effect: blurEffect)
view.frame = UIScreen.main.bounds
view.alpha = 0
return view
}()

public init(contentView: UIView, supportBlurView: Bool = true) {
self.contentView = contentView
self.supportBlurView = supportBlurView
super.init(nibName: nil, bundle: nil)
modalPresentationStyle = .custom
transitioningDelegate = self
Expand Down Expand Up @@ -41,6 +51,9 @@ extension PopupViewController: UIViewControllerTransitioningDelegate {
} else {
transitionAnimator.alertTransitionPosition = .right
}
if supportBlurView {
showBlurEffectView(source: source, duration: transitionAnimator.duration)
}
return transitionAnimator
}

Expand All @@ -52,6 +65,29 @@ extension PopupViewController: UIViewControllerTransitioningDelegate {
} else {
transitionAnimator.alertTransitionPosition = .right
}
if supportBlurView {
hiddenBlurEffectView(duration: transitionAnimator.duration)
}
return transitionAnimator
}

private func showBlurEffectView(source: UIViewController, duration: TimeInterval) {
source.view.addSubview(blurEffectView)
UIView.animate(withDuration: duration) { [weak self] in
guard let self = self else { return }
self.blurEffectView.alpha = 1
}
}

private func hiddenBlurEffectView(duration: TimeInterval) {
UIView.animate(withDuration: duration) { [weak self] in
guard let self = self else { return }
self.blurEffectView.alpha = 0
} completion: { [weak self] finished in
guard let self = self else { return }
if finished {
self.blurEffectView.removeFromSuperview()
}
}
}
}

0 comments on commit 8e2505b

Please sign in to comment.