有沒有辦法禁用MPMoviePlayerController的全屏按鈕?iPad MPMoviePlayerController - 禁用全屏
回答
不,沒有辦法。希望下一次更新。
可以隱藏播放控件,並添加自己的自定義的,這將防止在所有
即被渲染與
[player setMovieControlMode:MPMovieControlModeNone];
根據您的需要默認的按鈕,你也可以簡單地禁用玩家視圖上的所有用戶交互。
player.view.userInteractionEnabled = NO;
有線這樣做。對於以全屏開始的視頻,它們具有標準的MPMoviePlayerController控件,但缺少全屏按鈕。而且他們使用標準的內置按鈕,因爲他們突然得到了4.2版的AirPlay按鈕。
有一個作弊:
MPMoviePlayerController *mpc = (...some instance...)
UIView *fsbutton = [[mpc view] viewWithTag:512];
[fsbutton setHidden:YES];
主要的前提條件是,你必須這樣做,在viewDidAppear:
或類似的,因爲MoviePlayer視圖某處把它自己內部didMoveToWindow
或didMoveToSuperview
,viewWillAppear:
之後發生。所以你會看到全屏按鈕的短暫閃爍。其他明顯的變化包括:脆弱與蘋果改變512標籤值(儘管它在3.2 - 4.2中工作);當然蘋果公司寧願你不這樣做。
認可的解決方案是將控制樣式設置爲MPMovieControlStyleNone
並滾動您自己的傳輸控件,這是更多的工作。
另一個問題是,捏縮放手勢也帶來了用戶進入全屏規避這個不錯的主意。 – Roger 2011-04-21 08:37:02
並嘗試刪除手勢 – SAKrisT 2013-01-02 10:06:48
蘋果很可能會拒絕你的應用程序,如果你試圖修改MPMovePlayerController超出了公共API。下面是從[蘋果的文檔(https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html)報價: 「考慮一個電影播放器視圖是一個不透明結構。您可以添加自己的自定義子視圖層上影片的上方內容,但你**絕不能修改任何現有的子視圖。**」 – n8tr 2014-01-28 15:38:58
只是做它:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieEventFullscreenHandler:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieEventFullscreenHandler:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}
- (void)movieEventFullscreenHandler:(NSNotification*)notification {
[self.moviePlayer setFullscreen:NO animated:NO];
[self.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
}
與暫停鍵一起全屏按鈕,可以刪除。
[self.videoPlayer setControlStyle:MPMovieControlStyleNone];
以禁用切換到全屏模式,無論是外形按鈕或縮放手勢,您可以使用此:
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.userInteractionEnabled =NO;
我知道,這是一個有點過時,但無論如何。我在這方面做了一些研究,看起來像找到了答案。我不知道,爲什麼它在工作,但它是。
-(void) playMovieAtURL: (NSURL*) theURL {
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
//That line is for ARC. Without it, it may not work.
self.moviePlayer = theMovie;
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.controlStyle = MPMovieControlStyleFullscreen;
theMovie.repeatMode = MPMovieRepeatModeOne;
//Here you'd better use your custom ViewController subclass, if you want autorotating and all that stuff.
UIViewController * vc = [UIViewController new];
[vc.view addSubview:theMovie.view];
theMovie.fullscreen = YES;
theMovie.view.frame = vc.view.bounds;
vc.view = theMovie.view;
[self presentModalViewController:vc animated:YES];
theMovie.fullscreen = YES;
[theMovie prepareToPlay];
[theMovie play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
//當電影完成時,釋放控制器。
-(void) myMovieFinishedCallback: (NSNotification*) aNotification
{
[self dismissModalViewControllerAnimated:YES];
MPMoviePlayerController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
[self.moviePlayer.view removeFromSuperview];
self.moviePlayer = nil;
// Release the movie instance created in playMovieAtURL:
}
如果你想要做的唯一事情禁用是掐去全屏幕(即保持互動啓用,任何你想要的控制方式),您可以使用此:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *set = [event allTouches];
NSArray *arr = [set allObjects];
for (int i = 0; i < arr.count; i++) {
UITouch *touch = (UITouch *) [arr objectAtIndex:i];
NSArray *recognisers = touch.gestureRecognizers;
for (UIGestureRecognizer *recogniser in recognisers) {
if (recogniser.enabled && [recogniser isMemberOfClass:[UIPinchGestureRecognizer class]]) {
recogniser.enabled = NO;
}
}
}
}
簡單的塊刪除這裏
雙指縮放希望這有助於
它與我iOS6的
工作for (UIView *view in moviePlayer.view.subviews) {
for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
[view removeGestureRecognizer:pinch];
}
}
您可以將controlStyle設置爲全屏。這些控件有些不同,但它不具有全屏按鈕!
[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
天才!這一定要最好的答案。 – PICyourBrain 2015-03-11 20:47:49
這適用於iOS 7,iPhone 5s。
Add Notification:
MPMoviePlayerDidEnterFullscreenNotification : @"moviePlayFullscreenNote:"
- (void)moviePlayFullscreenNote:(NSNotification*)notification
{
if (notification.object == self.videoPlayer)
{
[self.videoPlayer setFullscreen:NO animated:YES];
self.videoPlayer.controlStyle = MPMovieControlStyleEmbedded;
}
}
請注意,我只會偵聽「DID」而不是「WILL」通知以及運行動畫。我認爲這是有效的,因爲它會讓系統有時間做出反應。當我使用上述答案中提到的「WILL」和「DID」時,會導致黑屏而無法控制。發生轉換時會出現輕微的小故障,但我需要嵌入式播放/擦洗按鈕。
不幸的是上面這些都不是爲我工作正常,所以我選擇來實現上述以下(和工作正常):
- 隱藏的全屏按鈕。
在初始化電影播放器的方法中添加此代碼。
.... //Because we have to wait until controllers are shown [self performSelector:@selector(hideFullscreenButton) withObject:self afterDelay:0.5]; ...
添加方法:
-(void) hideFullscreenButton{ //Hide full screen mode button [self hideFullscreenSubview:movieClip.view.subviews]; } -(void) hideFullscreenSubview:(NSArray*)arr{ for(UIView *v in arr){ if([v.subviews count]>0) [self hideFullscreenSubview:v.subviews]; else NSLog(@"%@",v); if(v.frame.origin.x==975){ v.hidden=TRUE; } } }
問題依賴,沒有標籤,以識別哪些查看你要隱藏。在我的情況下,我通過視圖座標來確定它。
- 覆蓋輕敲手勢,不允許全屏縮放。
movieClip.controlStyle = MPMovieControlStyleEmbedded; //Disable tap for not allowing that video control set on a full screen mode. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)]; singleTap.numberOfTapsRequired = 1; [movieClip.view addGestureRecognizer:singleTap]; UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doDoubleTap)]; doubleTap.numberOfTapsRequired = 2; [movieClip.view addGestureRecognizer:doubleTap]; [singleTap requireGestureRecognizerToFail:doubleTap];
並添加選擇的方法:
-(void) doSingleTap{ //DO NOTHING!!! } -(void) doDoubleTap{ //DO NOTHING!!! }
第一個解決方案的工作非常適合我, THX!在底部的斯威夫特版本 – diegomen 2016-03-29 12:26:03
它隱藏洗滌器不是全屏按鈕 – 2016-04-30 13:02:27
將一個或UIView
與UIButton
上示出視頻,從而用戶將不能夠到視圖的頂部透明背景點擊包含視頻的視圖。
這是哈維爾拉瓦Llavería的第一溶液的夫特版本:和
func hideFullScreenButton() {
self.hideFullScreenSubview((self.moviePlayerController?.view.subviews)!)
}
func hideFullScreenSubview(subviews: [UIView]) {
for view: UIView in subviews {
if view.subviews.count > 0 {
self.hideFullScreenSubview(view.subviews)
}
if view.frame.origin.x == 631 {
view.hidden = true
}
}
}
當用戶輕敲上玩:
self.performSelector(#selector(VideoViewController.hideFullScreenButton), withObject: self, afterDelay: 0.5)
(VideoViewController是其中我視圖控制器MPMoviePlayerController)
- 1. MPMoviePlayerController在iPad中的全屏怪癖
- 2. mpmovieplayercontroller全屏問題?
- 3. MPMoviePlayerController全屏鎖定
- 4. MPMoviePlayerController,禁止全屏,但允許通過剪輯導航?
- 5. iOS - 禁用MPMoviePlayerController全屏的雙指縮放
- 6. iPad MPMoviePlayerController全屏旋轉移動所有視圖
- 7. 正確顯示和iOS 3.2(iPad版)駁回全屏的MPMoviePlayerController
- 8. mpmovieplayercontroller問題ipad
- 9. MPMoviePlayerController全屏模式問題
- 10. MPMoviePlayerController全屏不工作
- 11. 全屏iPad UIPopoverController
- 12. ipad UITableViewController全屏
- 13. MPMoviePlayerController隱藏全屏控制器
- 14. iPad版全屏API?
- 15. iOS在全屏幕(iPad)中使用MPMoviePlayerViewController
- 16. MPMoviePlayerController for iPhone App在iPad上
- 17. 在ipad上禁用vimeo上的全屏選項
- 18. 在MPMoviePlayerController中播放全屏.mp4視頻?
- 19. ios MPMoviePlayerController強制橫向全屏
- 20. MPMoviePlayerController UIWebView內的全屏電影
- 21. 全屏MPMoviePlayerController界面方向更改
- 22. 在全屏模式下添加MPMoviePlayerController?
- 23. MPMoviePlayerController在全屏添加子視圖
- 24. 全屏圖像捏ipad
- 25. 使用MPMoviePlayerController禁用AirPlay
- 26. iPad MPMoviePlayerController UISplitView中的iOS 5.1問題
- 27. iPad上的MPMoviePlayerController問題
- 28. iPad 3.2和[MPMoviePlayerController setFullScreen:]沒有顯示
- 29. MPMoviePlayerController在全屏模式後以錯誤的方向離開應用程序
- 30. MPMoviePlayerController在iPad上播放錯誤
:( 謝謝! – MathieuF 2010-09-29 13:30:24