[英]MPMoviePlayerViewController customization
我正在使用MPMoviePlayerViewController - 播放器控件設置為:MPMovieControlStyleFullscreen
我對MPMovieControlStyleFullscreen中的一些按鈕有問題:前進,后退和全屏(箭頭指向彼此的那個)。
我想要刪除前進,后退和全屏按鈕,或者控制用戶點擊它們時的操作。
謝謝!
沒有辦法自定義Apple提供的MPMovieControlStyle
值。 你需要做的是關閉Apple控件( MPMovieControlStyleNone
),然后創建自己的自定義控件。 Apple可以將您自己的UIViews放入層次結構中,因此您可以開始使用以下內容:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: YOUR_URL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
UIView *movieView = moviePlayer.view;
[movieView addSubview: _movieControlsView];
[movieView bringSubviewToFront: _movieControlsView];
其中_movieControlsView
是在代碼或IB中設置的。
在美學上,你可以做你想做的事,但我建議堅持使用看起來像Apple的選擇,以免混淆用戶。 對於我剛剛完成的項目,我創建了一個透明按鈕,與電影播放器的大小完全相同。 單擊按鈕會使用我的自定義控件淡化底部的控制欄。 如果未單擊其中一個控件,控制欄將在幾秒鍾后再次退出。
首先,MPMoviePlayerController與MPMoviePlayer * View * Controller略有不同,因此在轉換iOS 4.3+環境中構建的應用程序時,其中一些答案會導致問題。
我使用MPMoviePlayerController構建了一些應用程序,這些應用程序在iOS 3.2中構建時運行良好。 當我使用XCode 3.2.6(iOS 4.3)重建它時,視頻甚至無法在iPhone上播放。 我通過將MPMoviePlayerController實例添加到subView來修復它,然后在fullScreenMode中使用movplayer呈現一個模態(Player是一個UIViewController):
//from didSelectRowAtIndexPath
Vid *selected = [items objectAtIndex:position];
player = [[Player alloc] init];
movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
movplayer.view.frame = player.view.bounds;
movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[player.view addSubview:movplayer.view];
[self presentModalViewController:player animated:YES];
[movplayer setFullscreen:YES animated:NO];
[movplayer play];
[player release];
//movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification
這是因為UINavigationBar在旋轉時被切斷了一半 。
當我進入應用程序的iPad版本時,模態選項在美學上不會起作用。 在全屏模式下旋轉時,它還有UISplitViewController導航條和工具欄的一半切斷。 所以我嘗試實現MPMoviePlayerViewController而不是MPMoviePlayerController。 通過此轉換,XCode在嘗試設置時給出了錯誤:
movplayer.controlStyle = MPMovieControlStyleEmbedded;
使用MPMoviePlayerViewController執行此操作的正確方法是:
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
當播放器作為子視圖添加時,捏合手勢將平滑地在fullScreen和parentView(player.view.bounds)的大小之間切換播放器,以及保留父級的工具欄和導航欄本機。
//iPad version with a view (viewForMovie) inside the DetailViewController
movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
movplayer.view.backgroundColor = [UIColor clearColor];
movplayer.view.frame = viewForMovie.bounds;
[viewForMovie addSubview:movplayer.view];
因此,這兩個示例顯示了那些想要將iPhone或iPad應用程序轉換為較新iOS版本的人的一些解決方法。
嘗試設置MPMovieControlStyle
您的MPMoviePlayerController
對象MPMovieControlStyleNone
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.