假設iOS 3.2或更高版本。什麼是適當的命令序列,用最初隱藏的控件進行移動。當電影播放時,用戶可以選擇在屏幕上標記並顯示控件。如何在播放MPMoviePlayerController電影之前隱藏控件?
謝謝!
我(控制不是隱藏)代碼:
- (void)playMovie
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Test" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieState:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieReady:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
moviePlayer.controlStyle = MPMovieControlStyleDefault; // MPMovieControlStyleNone MPMovieControlStyleEmbedded MPMovieControlStyleFullscreen MPMovieControlStyleDefault
moviePlayer.scalingMode = MPMovieScalingModeAspectFill; // MPMovieScalingModeAspectFit MPMovieScalingModeAspectFill
}
}
- (void) movieReady:(NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];
if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
// When tapping movie, status bar will appear, it shows up
// in portrait mode by default. Set orientation to landscape
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// Add movie player as subview
[[self view] addSubview:[moviePlayer view]];
// Play the movie
[moviePlayer play];
[moviePlayer setFullscreen:YES animated:YES];
}
}
好的提示。我還發現,如果我在調用play後立即將控制風格設置爲'MPMovieControlStyleFullscreen',它會達到相同的結果。那麼也許沒有理由指定任意1秒的延遲? – curthipster 2011-06-07 23:34:19
一秒鐘延遲也適用於我。我試了半秒,但那太快了。 – 2011-10-02 17:53:28
是的,我也需要延遲仍然想知道爲什麼我需要引入這樣的延遲。 – 2014-02-25 07:19:20