如何将 KVO 添加到 MPMoviePlayerController 以便我可以检测控件何时可见

发布于 2024-12-01 01:01:33 字数 103 浏览 0 评论 0原文

我希望能够使用 MPMoviePlayerController 的标准控件来显示和消失我的自定义控件。最好的方法是什么?

谢谢,

罗布

I want to be able to make my custom controls appear and disappear with the standard control for a MPMoviePlayerController. What is the best approach?

Thanks,

Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ヤ经典坏疍 2024-12-08 01:01:33

我相信我找到了解决方案。如果其他人需要此功能,以下是我如何让它工作:

我使用了我找到的代码 此处可在 MPMoviePlayer 视图数组中查找 MPInlineVideoOverlay 子视图。然后我修改如下:


- (void)observeValueForKeyPath:(NSString *)keyPath 
                          ofObject:(id)object 
                            change:(NSDictionary *)change 
                           context:(void *)context {

float newValue = 0; if([change objectForKey:NSKeyValueChangeNewKey] != [NSNull null]) { newValue = [[change objectForKey:NSKeyValueChangeNewKey] floatValue]; } NSLog(@"player controls are visible: %@", newValue ? @"YES" : @"NO"); self.controlsView.alpha = newValue; } -(void)recursiveViewTraversal:(UIView*)view counter:(int)counter { NSLog(@"Depth %d - %@", counter, view); //For debug if([view isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")]) { //Add any additional controls you want to have fade with the standard controls here mainControlsView = view; } else { for(UIView *child in [view subviews]) { [self recursiveViewTraversal:child counter:counter+1]; } } } -(void)setupAdditionalControls { //Call after you have initialized your MPMoviePlayerController (probably viewDidLoad) mainControlsView = nil; [self recursiveViewTraversal:moviePlayer.view counter:0]; //check to see if we found it, if we didn't we need to do it again in 0.1 seconds if(mainControlsView) { [mainControlsView addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:NULL]; } else { [self performSelector:@selector(setupAdditionalControls) withObject:nil afterDelay:0.1]; } }`

其中 mainControlsView 是 MPMoviePlayer 的标准 Apple 控件,而 self.controlsView 是我的带有自定义控件的视图。 I 键值 观察标准控件视图上的 alpha 属性,并在其更改时更改我的属性以匹配。

I believe I found the solution. If anyone else needs this functionality, here is how I got it to work:

I used the code I found here to find the MPInlineVideoOverlay subview in the MPMoviePlayer view array. Then I modified it as follows:


- (void)observeValueForKeyPath:(NSString *)keyPath 
                          ofObject:(id)object 
                            change:(NSDictionary *)change 
                           context:(void *)context {

float newValue = 0; if([change objectForKey:NSKeyValueChangeNewKey] != [NSNull null]) { newValue = [[change objectForKey:NSKeyValueChangeNewKey] floatValue]; } NSLog(@"player controls are visible: %@", newValue ? @"YES" : @"NO"); self.controlsView.alpha = newValue; } -(void)recursiveViewTraversal:(UIView*)view counter:(int)counter { NSLog(@"Depth %d - %@", counter, view); //For debug if([view isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")]) { //Add any additional controls you want to have fade with the standard controls here mainControlsView = view; } else { for(UIView *child in [view subviews]) { [self recursiveViewTraversal:child counter:counter+1]; } } } -(void)setupAdditionalControls { //Call after you have initialized your MPMoviePlayerController (probably viewDidLoad) mainControlsView = nil; [self recursiveViewTraversal:moviePlayer.view counter:0]; //check to see if we found it, if we didn't we need to do it again in 0.1 seconds if(mainControlsView) { [mainControlsView addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:NULL]; } else { [self performSelector:@selector(setupAdditionalControls) withObject:nil afterDelay:0.1]; } }`

Where mainControlsView is the standard Apple controls for MPMoviePlayer and self.controlsView is my view with my custom controls. I Key Value Observe the alpha property on the standard controls view and change mine to match whenever it changes.

Rob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文