2013-06-01 92 views
3

我想從視圖控制器播放視頻。當我呈現它時,它會呈現出像縱向一樣的視角,所以視角就會轉向。它只發生在iPhone上,而不是iPad上。presentViewController更改控制器的方向

有一個的ViewController> MyItemsController>的視頻控制器

enter image description here

當我關閉的視頻控制器,父控制器,視頻控制器的(MyItemsController)是這樣的:的

enter image description here

故事板視圖控制器是:

enter image description here

而且代碼:

-(void)playMoviesForItems:(NSArray *)shopItems{ 
    VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:@"videoPlayerController"]; 
    moviePlayer.modalPresentationStyle = UIModalPresentationCurrentContext; 
    moviePlayer.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentViewController:moviePlayer animated:NO completion:nil]; 
} 

我感動的代碼到應用程序的委託:

-(void)playMoviesForItems:(NSArray *)shopItems{ 
VideoPlayerViewController* mp = [[self getStoryboard] instantiateViewControllerWithIdentifier:@"videoPlayerController"]; 
[mp playMoviesForItems:shopItems]; 
[self pauseBackgroundMusic]; 

[self.window makeKeyAndVisible]; 
[self.window.rootViewController presentViewController:mp animated:YES completion:NULL]; 
} 

這個時候,一切似乎是好。電影正在播放,我可以聽到聲音,但看不到視頻。爲什麼? enter image description here

+0

你想鎖定在特定方向的應用程序? – Mar0ux

+0

我通常將其鎖定在橫向模式下。但是這個控制器就像iPhone中那樣。 iPad是正常的。 – Burak

+0

你有沒有解決這個問題?我有同樣的問題:( –

回答

1

雖然接受的答案被向下投票,因爲它沒有回答這個問題,這裏的東西,在iOS9工作:

呈現在視圖控制器時調用的方法(模態)是preferredInterfaceOrientationForPresentation。此方法必須返回一個方向。
您應該檢查演示者的方位,並返回它作爲首選:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
     UIInterfaceOrientation topOrientation = self.navigationController.visibleViewController.interfaceOrientation; 
     UIInterfaceOrientation presentingOrientation = self.presentingViewController.interfaceOrientation; 

     return presentingOrientation ? presentingOrientation : topOrientation ? topOrientation : UIInterfaceOrientationLandscapeLeft; 
} 

topOrientation包含可見視圖控制器的方向,而presentingOrientation是的叫presentViewController:animated... 總體方向,我建議你創建一個「基」UIViewController類,並從中繼承。通過這種方式,所有視圖控制器都將受益於此代碼。

0

確保在孩子視圖控制器添加這兩個:

- (UIInterfaceOrientationMask) supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); 
} 
+0

我已經添加了此 – Burak

+0

和'應用:supportedInterfaceOrientationsForWindow:''中AppDelegate' – Mar0ux

+0

我說 - (NSUInteger)應用:?(UIApplication的*)應用程序supportedInterfaceOrientationsForWindow:(*的UIWindow)W { 返回(NSUInteger)[應用程序supportedInterfaceOrientationsForWindow:w] |(1 << UIInterfaceOrientationMaskLandscape); }但它不起作用 – Burak

-1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationMaskLandscape); 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskLandscape); 
} 

嘗試......

+0

我試過了不行的 – Burak

+0

試試這個...告訴我結果... – lakesh

+0

沒有任何改變 – Burak

0

必須添加下面的方法,在你的自我。 window.rootViewController'class:

-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 


@end 

如果你的RootViewController的是[UINavigationController的類],命令+ N添加的UINavigationController的類別,比如我下面的代碼

@implementation UINavigationController (Rotation_For_iOS6) 

-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 


@end 

,然後,去哪個ü要成爲橫向或縱向模式的viewController.m,也許因爲你是你的VideoController !!!!!!下面 添加方法:

#pragma mark 
#pragma mark ----- Orientation Control For iOS 6/7 ----- 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight||toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 

現在我將支持橫向模式我的VC,最後但並非最不重要的,請確保您的項目部署信息選擇方向你想要的。

1

幾分鐘前我有這個完全相同的問題。

發生了什麼事我是,我是想提出新的ViewController與另一ViewController這是不是在層次結構,它只有它的視圖中添加的層次結構中的第三ViewControllersubview。爲了解決這個問題,我只是讓這個最後的ViewController提出了新的問題。什麼不該做

舉例:應該怎樣做,而不是

UIViewController *secondController = [UIViewController alloc] init]; 
[rootViewController presentViewController:secondController animated:NO completion:nil]; 

UIViewController *controllerOutsideHierarchy = [UIViewController alloc] init]; 
[secondController.view addSubview:controllerOutsideHierarchy.view]; 

[controllerOutsideHierarchy presentViewController:thirdController animated:NO completion:nil]; 

例子:

UIViewController *secondController = [UIViewController alloc] init]; 
[rootViewController presentViewController:secondController animated:NO completion:nil]; 

UIViewController *controllerOutsideHierarchy = [UIViewController alloc] init]; 
[secondController.view addSubview:controllerOutsideHierarchy.view]; 

[secondController presentViewController:thirdController animated:NO completion:nil]; 

希望這有助於!

相關問題