gpt4 book ai didi

ios - 如何在 UIWebView Video Player 中添加 OverLay View?

转载 作者:IT王子 更新时间:2023-10-29 07:58:09 27 4
gpt4 key购买 nike

我想在 UIWebView 的视频播放器上添加一些自定义控件。我可以通过以下代码添加对它的任何控制:

首先我在下面添加通知,

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addOverLayView:) name:UIWindowDidBecomeVisibleNotification object:nil]; 

然后在收到它时,

-(void)addOverLayView:(NSNotification*)aNotification{
UIWindow *window = (UIWindow *)aNotification.object;

if (window != self.view.window) {
[window addSubview:anyCustomview];
}
}

但此 View 将静态地位于 UIWebView 的视频 View 之上。但我想实现像视频播放器的控件隐藏时我想隐藏我的自定义 View 。

换句话说,我想在 UIWebView 的视频播放器 View 上实现自定义 OverLayView

最佳答案

似乎不可能“开箱即用”。文档指出电影播放器​​在这些情况下发出通知:

When the movie player begins playing, is paused, or begins seeking forward or backward
When AirPlay playback starts or ends
When the scaling mode of the movie changes
When the movie enters or exits fullscreen mode
When the load state for network-based movies changes
When meta-information about the movie itself becomes available

因此无法知道控件何时隐藏/显示。

如果你只想显示一次 View ,在用户打开 View 后,你可以很容易地实现这一点,例如使用动画:

-(void)addOverLayView:(NSNotification*)aNotification{
UIWindow *window = (UIWindow *)aNotification.object;

if (window != self.view.window) {
[window addSubview:anyCustomview];

[UIView animateWithDuration:2 //choose a fitting value here
delay:3 //this has to be chosen experimentally if you want it to match with the timing of when the controls hide
options:UIViewAnimationOptionCurveEaseOut
animations:^{
anyCustomView.alpha = 0.0f; //fadeout animation, you can leave this block empty to have no animation
} completion:^(BOOL finished) {
[anyCustomView removeFromSuperview];
}];
}
}

请注意,当用户放弃控件时,这不会隐藏您的 View 。

如果您想在每次显示/隐藏控件时都显示/隐藏您的 View ,那就更棘手了。一种方法是禁用标准控件并重新创建它们 - 请记住,这并不容易。

关于ios - 如何在 UIWebView Video Player 中添加 OverLay View?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31473841/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com