2014-03-14 58 views

回答

1

爲什麼不強制你的控制器只能在橫向模式?

你可以這樣說:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 
+0

但是當我從cameara卷看它的視頻旋轉。必須平行於水平線 – user3419170

+0

規格:當我們使用原生ios相機記錄。當我們錄製視頻並旋轉屏幕上的設備視頻不旋轉時,但當我們觀看他時,視頻會在播放器上旋轉。我想製作一些像錄製視頻一樣的東西(視頻錄製,當設備旋轉時不旋轉,在播放器視頻不旋轉時,它將並行到水平) – user3419170

+0

好了。當用戶開始錄製視頻時,您必須鎖定旋轉角度。我想你應該允許旋轉而不錄製。 –

1

你可以試試這個代碼

@implementation PortraitViewController 
- (void)awakeFromNib 
{ 
    isShowingLandscapeView = NO; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
           selector:@selector(orientationChanged:) 
           name:UIDeviceOrientationDidChangeNotification 
           object:nil]; 
} 

- (void)orientationChanged:(NSNotification *)notification 
{ 
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && 
     !isShowingLandscapeView) 
    { 
     [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self]; 
     isShowingLandscapeView = YES; 
    } 
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) && 
      isShowingLandscapeView) 
    { 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     isShowingLandscapeView = NO; 
    } 
} 

也對蘋果的文檔HERE查看詳細轉動實現的樣子。