This commit is contained in:
2025-11-27 21:39:03 +08:00
parent 3144315de5
commit c37038f163
3 changed files with 90 additions and 18 deletions

Binary file not shown.

View File

@@ -6,11 +6,11 @@
//
#import "KBPermissionViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface KBPermissionViewController ()
@property (nonatomic, strong) UILabel *titleLabel; //
@property (nonatomic, strong) UILabel *tipsLabel; //
@property (nonatomic, strong) UIView *cardView; //
@property (nonatomic, strong) UIButton *openButton; //
@property (nonatomic, strong) UIButton *closeButton; //
@@ -19,6 +19,10 @@
@property (nonatomic, strong) UIImageView *bgImageView;
//
@property (nonatomic, strong) AVPlayer *kb_permPlayer;
@property (nonatomic, strong) AVPlayerLayer *kb_permPlayerLayer;
@end
@implementation KBPermissionViewController
@@ -32,7 +36,7 @@
[self.view addSubview:self.closeButton];
[self.view addSubview:self.titleLabel];
[self.view addSubview:self.tipsLabel];
[self.view addSubview:self.cardView];
// [self.view addSubview:self.videoContainerView];
[self.view addSubview:self.openButton];
[self.view addSubview:self.helpLabel];
@@ -66,11 +70,13 @@
make.left.equalTo(self.titleLabel);
}];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.openButton.mas_top).offset(-36);
make.left.right.equalTo(self.view).inset(56);
make.top.equalTo(self.tipsLabel.mas_bottom).offset(36);
}];
// view 16 tipsLabel 30 36
// [self.videoContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(self.tipsLabel.mas_bottom).offset(30);
// make.left.equalTo(self.view).offset(16);
// make.right.equalTo(self.view).offset(-16);
// make.bottom.equalTo(self.openButton.mas_top).offset(-36);
// }];
[self.openButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(-KB_SAFE_BOTTOM-20);
@@ -86,6 +92,30 @@
// }];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//
[self kb_setupPermissionVideoPlayer];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
//
[self.kb_permPlayer pause];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (!self.kb_permPlayerLayer) { return; }
// videoGravity
self.kb_permPlayerLayer.frame = CGRectMake(25, CGRectGetMaxY(self.tipsLabel.frame) + 32, KB_SCREEN_WIDTH - 50, 700);
}
- (void)dealloc {
//
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Actions
- (void)onBack {
@@ -129,6 +159,55 @@
[self.navigationController popViewControllerAnimated:true];
}
#pragma mark - Video Player
// cardView
- (void)kb_setupPermissionVideoPlayer {
//
if (self.kb_permPlayer) {
[self.kb_permPlayer play];
return;
}
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:@"permiss_video" withExtension:@"mp4"];
if (!videoURL) {
return;
}
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:videoURL];
self.kb_permPlayer = [AVPlayer playerWithPlayerItem:item];
self.kb_permPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
self.kb_permPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.kb_permPlayer];
// 使 frame
self.kb_permPlayerLayer.videoGravity = AVLayerVideoGravityResize;
self.kb_permPlayerLayer.cornerRadius = 20;
self.kb_permPlayerLayer.masksToBounds = true;
//
CALayer *buttonLayer = self.openButton.layer;
[self.view.layer insertSublayer:self.kb_permPlayerLayer below:buttonLayer];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(kb_playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:item];
[self.kb_permPlayer play];
}
- (void)kb_playerItemDidReachEnd:(NSNotification *)note {
AVPlayerItem *item = (AVPlayerItem *)note.object;
if (!item) return;
__weak typeof(self) weakSelf = self;
[item seekToTime:kCMTimeZero completionHandler:^(BOOL finished) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf.kb_permPlayer play];
}];
}
#pragma mark - Lazy Subviews
- (UIButton *)backButton {
@@ -164,17 +243,6 @@
return _tipsLabel;
}
- (UIView *)cardView {
if (!_cardView) {
_cardView = [UIView new];
_cardView.backgroundColor = [UIColor whiteColor];
_cardView.layer.cornerRadius = 16;
_cardView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.1].CGColor;
_cardView.layer.shadowOpacity = 1;
_cardView.layer.shadowRadius = 12;
}
return _cardView;
}
- (UIButton *)openButton {
if (!_openButton) {