2012-12-07 50 views
0

我在ios6的方向有问题。相同的代码对ios5或5.1工作正常。 我按照ios6标准使用了- (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations。但仍然没有调用“willRotateToInterfaceOrientation”和“didRotateToInterfaceOrientation”。方向不适用于ios6?

这里是我的代码: -

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 

    if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) 
    if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) 
    { 

     CGRect frame; 
     int viewAlpha; 
     lastOrientation = toInterfaceOrientation; 

     if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 

      [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; 

      viewAlpha = 1; 
      [MovieControlContainerLandscape setHidden:YES]; 


      if (isDauntless) { 
       [self.navigationController setNavigationBarHidden:NO animated:YES]; 
      } else { 
       [self.navigationController setNavigationBarHidden:NO]; 
      } 


      frame = iPad ? CGRectMake(0, 88, 768, 432) : CGRectMake(0, 88, 320, 180); 
      [movieContainer removeGestureRecognizer:toggleMediaControl]; 


     } 
     else 
     { 
      [PromptToBuy dismissWithClickedButtonIndex:0 animated:YES]; 

      [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 

      viewAlpha = 0; 
      [MovieControlContainerLandscape.layer setCornerRadius:22]; 
      [MovieControlContainerLandscape.subviews.lastObject addSubview:[MediaControls use]]; 


      if (isDauntless) { 
       [self.navigationController setNavigationBarHidden:YES animated:YES]; 
      } else { 
       [self.navigationController setNavigationBarHidden:YES]; 
      } 


      frame = iPad ? CGRectMake(0, 0, 1024, 768) : CGRectMake(0, 0, 480, 320); 

      [movieContainer addGestureRecognizer:toggleMediaControl]; 

      if (isDauntless) { 
       [UIView beginAnimations:nil context:nil]; 
       [UIView setAnimationDuration:0.6]; 
      } 

      if(TSFullScreen) 
      { 
       [movieContainer setAlpha:1]; 
      } 

      if (isDauntless) { 
       [UIView commitAnimations]; 
      } 

     } 

     [viewContainer setAlpha:viewAlpha]; 

     // Size the overlay view for the current orientation. 
     [movieContainer setFrame:frame]; 

    } 

} 


/* Sent to the view controller after the user interface rotates. */ 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 

    if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) 
    if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)) 
    { 

     float duration = .5; 

     if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 

      if (isDauntless) { 
       [UIView transitionWithView:movieContainer duration:duration options:UIViewAnimationOptionTransitionNone animations:^{ 

        /* Move movie view to parent center. */ 
        [self.moviePlayerController.view setCenter:movieContainer.center]; 

       } completion:^(BOOL finished) { 

        [UIView beginAnimations:nil context:NULL]; 
        [UIView setAnimationDuration:duration]; 
        CGRect frame = movieContainer.frame; 
        /* Size movie view to fit parent view. */ 
        frame.origin.y = 0; 
        [self.moviePlayerController.view setFrame:frame]; 
        [UIView commitAnimations]; 

        CGPoint center = CGPointMake(movieContainer.center.x, -50); 
        [MovieControlContainerLandscape setTag:0]; 
        [MovieControlContainerLandscape setHidden:NO]; 
        [MovieControlContainerLandscape setCenter:center]; 

        [self toggleMovieController]; 

       }]; 

      } else { 

       CGRect frame = movieContainer.frame; 
       /* Size movie view to fit parent view. */ 
       frame.origin.y = 0; 
       [self.moviePlayerController.view setFrame:frame]; 

       CGPoint center = CGPointMake(movieContainer.center.x, -50); 
       [MovieControlContainerLandscape setTag:0]; 
       [MovieControlContainerLandscape setHidden:NO]; 
       [MovieControlContainerLandscape setCenter:center]; 

       [self toggleMovieController]; 

      } 


     } 
     else 
     { 

      if (!isDauntless) { 
       [MovieControlContainer setFrame:CGRectMake(0, 44, 768, 68)]; 
      } 

      [MovieControlContainer addSubview:[MediaControls use]]; 

      //NSLog(@"MovieControlContainer is %@, MovieControlContainer subviews: %@",MovieControlContainer,[MovieControlContainer subviews]); 


      if (isDauntless) { 
       [UIView beginAnimations:nil context:NULL]; 
       [UIView setAnimationDuration:duration]; 
      } 

      if(TSFullScreen){ 
       [movieContainer setAlpha:0]; 
      } 

      CGRect frame = movieContainer.frame; 
      /* Size movie view to fit parent view. */ 
      frame.origin.y = 0; 
      [self.moviePlayerController.view setFrame:frame]; 

      if (isDauntless) { 
       [UIView commitAnimations]; 
      } 

     } 

    } 

} 



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

     return !mediaTypeIsAudio && isOrientationSupported; 

} 



//----supported method for ios6--------// 


- (BOOL) shouldAutorotate 
{ 
    return YES; 
} 




-(NSInteger)supportedInterfaceOrientations{ 

    NSInteger mask = 0; 
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight]) 
     mask |= UIInterfaceOrientationMaskLandscapeRight; 
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft]) 
     mask |= UIInterfaceOrientationMaskLandscapeLeft; 
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait]) 
     mask |= UIInterfaceOrientationMaskPortrait; 
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown]) 
     mask |= UIInterfaceOrientationMaskPortraitUpsideDown; 
    return mask; 

} 

//i have set the rootviewcontroller in appdelegate file 
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; 
    self.window.rootViewController = self.navigationController. 

请帮我从这个问题冒了出来。我无法找到解决方案。感谢提前!!

+0

清洁香港我answer..http://stackoverflow.com/questions/13580386/iphone-风景问题/ 13586490#13586490 – Rajneesh071

+0

[无法处理iOS 6中的方向?](http://stackoverflow.com/questions/12519693/unable-to-handle-orientation-in-ios-6) – Pfitz

+1

Plz指导我如何实现与动画定向的事物就像我在上面的代码中为ios5所做的一样。我应该把这个代码放在ios6中。 !请帮我解决问题,并且不能从中解脱出来。 –

回答

0

ios6你必须使用这种方法vieworientation

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationMaskAll; 
} 

并检查我的答案Link

+1

但我的问题是,willRotateToInterfaceOrientation和didRotateToInterfaceOrientation没有被调用,其中主要功能是写入视频方向与动画。 –

+0

在ios 6中添加了上述方法。以前的方法不会调用。 – Rajneesh071

+1

那么我该如何实现ios6的视频方向定向动画呢? –

相关问题