我希望能够使用 MPMoviePlayerController 的标准控件使我的自定义控件出现和消失。最好的方法是什么?
谢谢,
罗伯
Best Answer-推荐答案 strong>
我相信我找到了解决方案。如果其他人需要这个功能,我是这样工作的:
我使用了我找到的代码 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/
|