English 中文(简体)
iPhone MPMoviePlayer obtain buttons view
原标题:

Can anyone suggest me how to obtain the view that contains all buttons from MPMoviePlayer ?

If you don t know, at least how you obtain the main view/window of the MPMoviePlayer.

UPDATE: I need to do this to add a button on the controller view. It would look something like this: Example http://img338.imageshack.us/img338/5184/poz.jpg

Thanks in advance!

最佳回答

You can t add it directly to the MPMoviePlayerController s view -- that s a private view and isn t accessible. If you want to add buttons, you need to create a transparent window over the top of everything and add the buttons to that.

Apple s MoviePlayer sample shows how to do this.

问题回答

The above answer is actually incorrect: the view is not private, and you can add views to it. You just have to dive deep enough to find it.

For example, in iOS 5.1, you can try something like this:

UIView *fullscreenOverlayView = [[[[[[[mpPlayer view] subviews] objectAtIndex:0] subviews] objectAtIndex:0] subviews] objectAtIndex:2];
[fullscreenOverlayView addSubview:ccButton];

This will add a CC button to the view, and if you specify the correct value for the frame of the CC button, it will insert the button to the control panel, and hide/show it with the control panel on touch. FYI: this is the frame I use:

BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);

// all of these values are just based on measurement on screen
// to make sure that the CC button "seems" to be part of the player s control panel
if (isPortrait)
{
    return CGRectMake(222, 880, 40, 40);
}
else {
    return CGRectMake(350, 625, 40, 40);
}

NOTE: the set of subviews of [mpPlayer view] are different for different iOS versions, so consider this as a work around only. There s no guarantee that this will work on iOS 6, and will crash on iOS 4.3.





相关问题
Moving a control around on the UI

We are developing in C#.Net. We are dynamically changing a .Net control s location based on mouse movement. The control moves on the screen as expected, but, if the mouse moved too quickly strange ...

iPhone MPMoviePlayer obtain buttons view

Can anyone suggest me how to obtain the view that contains all buttons from MPMoviePlayer ? If you don t know, at least how you obtain the main view/window of the MPMoviePlayer. UPDATE: I need to ...

C# Form Problem: new form losing control and randomly hiding

I m encountering strange behavior with forms on a c# 3.5 app. On a button click, my form1 hides itself, creates a new form2, and shows form2. Form1 also contains the event method triggered when ...

Synced Sliders in LabView

In LabView 2009, is there a way to have one control (slider) affect the output and display of another control (slider)? For example, there are two sliders that adjust two separate parameters. I ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Property binding across controls in WPF

I have two UserControls that I want to display in a Window. The value of the property "SelectedItem" of the first UserControl should be set to the second UserControl s "SelectedItem" property. How do ...

热门标签