• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 17:13:11 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

谢谢,

罗伯



Best Answer-推荐答案


我相信我找到了解决方案。如果其他人需要这个功能,我是这样工作的:

我使用了我找到的代码 here在 MPMoviePlayer View 数组中查找 MPInlineVideoOverlay subview 。然后我修改如下:


- (void)observeValueForKeyPathNSString *)keyPath 
                          ofObjectid)object 
                            changeNSDictionary *)change 
                           contextvoid *)context {<p></p>

    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)recursiveViewTraversalUIView*)view counterint)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 performSelectorselector(setupAdditionalControls) withObject:nil afterDelay:0.1];
    }
}`

其中 mainControlsView 是 MPMoviePlayer 的标准 Apple 控件,而 self.controlsView 是我的自定义控件 View 。 I Key Value 观察标准控件 View 上的 alpha 属性,并在它更改时更改我的以匹配。

罗伯

关于ios - 如何将 KVO 添加到 MPMoviePlayerController 以便我可以检测控件何时可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7163503/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap