在 AVPLayerViewController 中添加 activity 指标? (注意:当视频处于全屏模式时)
Add activity indicator in AVPLayerViewController ? (Note: When video is in fullscreen mode)
enter image description here如何在AVPLayerViewController全屏模式下在中间添加activity指示器?
您可以通过在主键上添加自定义视图来在 AVPLayerViewController 中心添加自定义指示器视图 window。
UIApplication.shared.keyWindow?.addSubview(your custom indicator view)
您可以如下设置自定义指标视图的中心。
activity.center = CGPoint.init(x: UIScreen.main.bounds.size.width/2.0, y: UIScreen.main.bounds.height/2.0)
当用户按下播放按钮时添加此代码
if(playerViewController.view.subviews.count != 0)
{
UIView *AVTouchIgnoringView = playerViewController.view.subviews[0].subviews.lastObject;
activityIndicatorBuffer.center = playerViewController.view.center;
[AVTouchIgnoringView addSubview:activityIndicatorView];
[AVTouchIgnoringView bringSubviewToFront:activityIndicatorView];
}
别忘了添加以下方法
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[playerViewController addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[playerViewController removeObserver:self forKeyPath:@"videoBounds"];
}
-(void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context
{
if ([keyPath isEqualToString:@"videoBounds"])
{
float height = playerViewController.contentOverlayView.bounds.size.height;
float width = playerViewController.contentOverlayView.bounds.size.width;
if (height == SCREEN_HEIGHT && width == SCREEN_WIDTH)
{
activityIndicatorBuffer.center = playerViewController.contentOverlayView.center;
}
else
{
activityIndicatorBuffer.center = playerViewController.view.center;
}
}
}
并且不要忘记在缓冲时开始动画。单击此处
enter image description here如何在AVPLayerViewController全屏模式下在中间添加activity指示器?
您可以通过在主键上添加自定义视图来在 AVPLayerViewController 中心添加自定义指示器视图 window。
UIApplication.shared.keyWindow?.addSubview(your custom indicator view)
您可以如下设置自定义指标视图的中心。
activity.center = CGPoint.init(x: UIScreen.main.bounds.size.width/2.0, y: UIScreen.main.bounds.height/2.0)
当用户按下播放按钮时添加此代码
if(playerViewController.view.subviews.count != 0)
{
UIView *AVTouchIgnoringView = playerViewController.view.subviews[0].subviews.lastObject;
activityIndicatorBuffer.center = playerViewController.view.center;
[AVTouchIgnoringView addSubview:activityIndicatorView];
[AVTouchIgnoringView bringSubviewToFront:activityIndicatorView];
}
别忘了添加以下方法
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[playerViewController addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[playerViewController removeObserver:self forKeyPath:@"videoBounds"];
}
-(void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context
{
if ([keyPath isEqualToString:@"videoBounds"])
{
float height = playerViewController.contentOverlayView.bounds.size.height;
float width = playerViewController.contentOverlayView.bounds.size.width;
if (height == SCREEN_HEIGHT && width == SCREEN_WIDTH)
{
activityIndicatorBuffer.center = playerViewController.contentOverlayView.center;
}
else
{
activityIndicatorBuffer.center = playerViewController.view.center;
}
}
}
并且不要忘记在缓冲时开始动画。单击此处