Skip to content

Commit ce83bfe

Browse files
chenlinJmoVxia
authored andcommitted
fix: 修复present导致外部控制器安全区域异常
fix: 修复UITableView和UICollectionView相关示例代码错误
1 parent dac33e7 commit ce83bfe

File tree

360 files changed

+18642
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+18642
-145
lines changed

.gitignore

Whitespace-only changes.

AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111
class AppDelegate: UIResponder, UIApplicationDelegate {
1212
var window: UIWindow?
1313
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
14-
window?.rootViewController = CLTabBarController()
14+
window?.rootViewController = CLTabBarController(nibName: nil, bundle: nil)
1515
window?.makeKeyAndVisible()
1616
return true
1717
}

CLCollectionViewController/CLCollectionViewController.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,18 @@ extension CLCollectionViewController {
148148
private extension CLCollectionViewController {
149149
func playWithIndexPath(_ indexPath: IndexPath) {
150150
guard let cell = collectionView.cellForItem(at: indexPath) else { return }
151+
let player = player ?? CLPlayer()
152+
self.player = player
151153

152-
if player == nil {
153-
player = CLPlayer()
154-
}
155-
player?.title = NSMutableAttributedString("这是一个标题", attributes: { $0
154+
player.title = NSMutableAttributedString("这是一个标题", attributes: { $0
156155
.font(.systemFont(ofSize: 16))
157156
.foregroundColor(.orange)
158157
.alignment(.center)
159158
})
160-
player?.url = URL(string: array[indexPath.row])
161-
cell.contentView.addSubview(player!)
162-
player?.frame = cell.contentView.bounds
163-
player?.play()
159+
player.url = URL(string: array[indexPath.row])
160+
cell.contentView.addSubview(player)
161+
player.frame = cell.contentView.bounds
162+
player.play()
164163
}
165164
}
166165

CLFrameController/CLFrameController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class CLFrameController: CLController {
2626
}()
2727

2828
private lazy var player: CLPlayer = {
29-
let view = CLPlayer(frame: CGRect(x: 0, y: UIApplication.shared.statusBarFrame.size.height + navigationBarHeight + 50, width: view.bounds.width, height: view.bounds.width / (16.0 / 9.0))) { config in
29+
let statusBarFrame = UIApplication.shared.connectedScenes
30+
.compactMap { $0 as? UIWindowScene }
31+
.first(where: { $0.activationState == .foregroundActive })?
32+
.statusBarManager?.statusBarFrame.height ?? 0
33+
let view = CLPlayer(frame: CGRect(x: 0, y: statusBarFrame + navigationBarHeight + 50, width: view.bounds.width, height: view.bounds.width / (16.0 / 9.0))) { config in
3034
config.videoGravity = .resizeAspectFill
3135
config.topBarHiddenStyle = .never
3236
config.isHiddenToolbarWhenStart = false

CLHomeController/Controller/CLHomeController.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,16 @@ extension CLHomeController {}
161161
private extension CLHomeController {
162162
func getAllowedAVPlayerFileExtensions() -> [String] {
163163
let avTypes = AVURLAsset.audiovisualTypes()
164-
var avExtensions = avTypes.map { UTTypeCopyPreferredTagWithClass($0 as CFString, kUTTagClassFilenameExtension)?.takeRetainedValue() as String? ?? "" }
165-
avExtensions = avExtensions.filter { !$0.isEmpty }
164+
var avExtensions: [String] = []
165+
166+
for avFileType in avTypes {
167+
let rawValue = avFileType.rawValue
168+
if let utType = UTType(rawValue),
169+
let ext = utType.preferredFilenameExtension
170+
{
171+
avExtensions.append(ext)
172+
}
173+
}
166174
return avExtensions
167175
}
168176

CLPlayer.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'CLPlayer'
4-
s.version = '2.0.7'
4+
s.version = '2.0.8'
55
s.summary = 'Swift版自定义AVPlayer'
66
s.description = <<-DESC
77
CLPlayer是基于系统AVPlayer封装的视频播放器.
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313
DESC
1414
s.homepage = 'https://github.com/JmoVxia/CLPlayer'
1515
s.license = { :type => 'MIT', :file => 'LICENSE' }
16-
s.authors = {'JmoVxia' => '269968846@qq.com'}
16+
s.authors = {'JmoVxia' => 'JmoVxia@gmail.com'}
1717
s.social_media_url = 'https://github.com/JmoVxia'
1818
s.swift_versions = ['5.0']
1919
s.ios.deployment_target = '12.0'

CLPlayer.xcodeproj/project.pbxproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@
484484
attributes = {
485485
BuildIndependentTargetsInParallel = 1;
486486
LastSwiftUpdateCheck = 1300;
487-
LastUpgradeCheck = 1540;
487+
LastUpgradeCheck = 1640;
488488
TargetAttributes = {
489489
5BA39B132727D147005059F5 = {
490490
CreatedOnToolsVersion = 13.0;
@@ -573,10 +573,14 @@
573573
inputFileListPaths = (
574574
"${PODS_ROOT}/Target Support Files/Pods-CLPlayer/Pods-CLPlayer-resources-${CONFIGURATION}-input-files.xcfilelist",
575575
);
576+
inputPaths = (
577+
);
576578
name = "[CP] Copy Pods Resources";
577579
outputFileListPaths = (
578580
"${PODS_ROOT}/Target Support Files/Pods-CLPlayer/Pods-CLPlayer-resources-${CONFIGURATION}-output-files.xcfilelist",
579581
);
582+
outputPaths = (
583+
);
580584
runOnlyForDeploymentPostprocessing = 0;
581585
shellPath = /bin/sh;
582586
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-CLPlayer/Pods-CLPlayer-resources.sh\"\n";
@@ -689,6 +693,7 @@
689693
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
690694
COPY_PHASE_STRIP = NO;
691695
DEBUG_INFORMATION_FORMAT = dwarf;
696+
DEVELOPMENT_TEAM = 533J5B8T42;
692697
ENABLE_STRICT_OBJC_MSGSEND = YES;
693698
ENABLE_TESTABILITY = YES;
694699
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -752,6 +757,7 @@
752757
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
753758
COPY_PHASE_STRIP = NO;
754759
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
760+
DEVELOPMENT_TEAM = 533J5B8T42;
755761
ENABLE_NS_ASSERTIONS = NO;
756762
ENABLE_STRICT_OBJC_MSGSEND = YES;
757763
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -790,12 +796,13 @@
790796
INFOPLIST_KEY_UIMainStoryboardFile = Main;
791797
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
792798
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
799+
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
793800
LD_RUNPATH_SEARCH_PATHS = (
794801
"$(inherited)",
795802
"@executable_path/Frameworks",
796803
);
797804
MARKETING_VERSION = 1.0;
798-
PRODUCT_BUNDLE_IDENTIFIER = com.CLPlayer.JmoVxia;
805+
PRODUCT_BUNDLE_IDENTIFIER = com.CLPlayer.JmoVxia.CC;
799806
PRODUCT_NAME = "$(TARGET_NAME)";
800807
SWIFT_EMIT_LOC_STRINGS = YES;
801808
SWIFT_VERSION = 5.0;
@@ -819,12 +826,13 @@
819826
INFOPLIST_KEY_UIMainStoryboardFile = Main;
820827
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
821828
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
829+
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
822830
LD_RUNPATH_SEARCH_PATHS = (
823831
"$(inherited)",
824832
"@executable_path/Frameworks",
825833
);
826834
MARKETING_VERSION = 1.0;
827-
PRODUCT_BUNDLE_IDENTIFIER = com.CLPlayer.JmoVxia;
835+
PRODUCT_BUNDLE_IDENTIFIER = com.CLPlayer.JmoVxia.CC;
828836
PRODUCT_NAME = "$(TARGET_NAME)";
829837
SWIFT_EMIT_LOC_STRINGS = YES;
830838
SWIFT_VERSION = 5.0;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>CLPlayer.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>5</integer>
11+
</dict>
12+
</dict>
13+
</dict>
14+
</plist>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
uuid = "02A9FB44-ED1E-4CF8-9E92-912DD8B9EB0D"
4+
type = "0"
5+
version = "2.0">
6+
</Bucket>

CLPlayer/CLFullScreenController/CLAnimationTransitioning.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ extension CLAnimationTransitioning {
2222
}
2323

2424
class CLAnimationTransitioning: NSObject {
25-
private let keyWindow: UIWindow? = {
26-
if #available(iOS 13.0, *) {
27-
return UIApplication.shared.windows.filter { $0.isKeyWindow }.last
28-
} else {
29-
return UIApplication.shared.keyWindow
25+
@discardableResult private func mainSync<T>(execute block: () -> T) -> T {
26+
guard !Thread.isMainThread else { return block() }
27+
return DispatchQueue.main.sync { block() }
28+
}
29+
30+
private var keyWindow: UIWindow? {
31+
mainSync {
32+
if #available(iOS 13.0, *) {
33+
UIApplication.shared.connectedScenes
34+
.compactMap { $0 as? UIWindowScene }
35+
.flatMap(\.windows)
36+
.first { $0.isKeyWindow }
37+
} else {
38+
UIApplication.shared.keyWindow
39+
}
3040
}
31-
}()
41+
}
3242

3343
private weak var playerView: CLPlayerView?
3444

@@ -89,7 +99,6 @@ extension CLAnimationTransitioning: UIViewControllerAnimatedTransitioning {
8999
toView.bounds = transitionContext.containerView.bounds
90100
toView.center = transitionContext.containerView.center
91101
transitionContext.completeTransition(true)
92-
UIViewController.attemptRotationToDeviceOrientation()
93102
}
94103
} else {
95104
guard let parentStackView = parentStackView else { return }
@@ -114,7 +123,6 @@ extension CLAnimationTransitioning: UIViewControllerAnimatedTransitioning {
114123
parentStackView.addArrangedSubview(playerView)
115124
fromView.removeFromSuperview()
116125
transitionContext.completeTransition(true)
117-
UIViewController.attemptRotationToDeviceOrientation()
118126
}
119127
}
120128
}

0 commit comments

Comments
 (0)