ios - 如何将 KVO 添加到 MPMoviePlayerController 以便我可以检测控件何时可见
<p><p>我希望能够使用 <code>MPMoviePlayerController</code> 的标准控件使我的自定义控件出现和消失。最好的方法是什么?</p>
<p>谢谢,</p>
<p>罗伯</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我相信我找到了解决方案。如果其他人需要这个功能,我是这样工作的:</p>
<p>我使用了我找到的代码 <a href="https://stackoverflow.com/questions/6113735/mpmovieplayercontroller-adding-uibutton-to-view-that-fades-with-controls" rel="noreferrer noopener nofollow">here</a>在 MPMoviePlayerView 数组中查找 MPInlineVideoOverlaysubview 。然后我修改如下:</p>
<p></p> <pre><code>
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {<p></p>
float newValue = 0;
if( != )
{
newValue = [ 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() {
//Add any additional controls you want to have fade with the standard controls here
mainControlsView = view;
} else {
for(UIView *child in ) {
;
}
}
}
-(void)setupAdditionalControls {
//Call after you have initialized your MPMoviePlayerController (probably viewDidLoad)
mainControlsView = nil;
;
//check to see if we found it, if we didn't we need to do it again in 0.1 seconds
if(mainControlsView) {
;
} else {
;
}
}`
</code></pre>
<p>其中 mainControlsView 是 MPMoviePlayer 的标准 Apple 控件,而 self.controlsView 是我的自定义控件 View 。 I Key Value 观察标准控件 View 上的 alpha 属性,并在它更改时更改我的以匹配。</p>
<p>罗伯</p></p>
<p style="font-size: 20px;">关于ios - 如何将 KVO 添加到 MPMoviePlayerController 以便我可以检测控件何时可见,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/7163503/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/7163503/
</a>
</p>
页:
[1]