Advertisement
Guest User

App rotations

a guest
May 28th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma mark - Application Orientations
  2.  
  3. /**
  4.  *  iPhone: rotate only full gallery view or while movie is being played
  5.  *  iPad: Lanscape only
  6.  *
  7.  *  @param application
  8.  *  @param window
  9.  *
  10.  *  @return the orientations
  11.  */
  12. - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
  13.     // Dont rotate for iPad. Allow to rotate if there is fullscreen video but while on iPhone or iPod,
  14.     // only playback video in landscape - while leaving the app itself in portrait only.
  15.     //
  16.     //iPad behaviour
  17.     if (INTERFACE_IS_IPAD)
  18.         return UIInterfaceOrientationMaskLandscape;
  19.    
  20.     //iPhone behaviour
  21.     NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;
  22.     UIWindow *keyWindow     = window; //[UIApplication sharedApplication].keyWindow;
  23.     if(keyWindow && keyWindow.rootViewController){
  24.         UIViewController *presentedViewController = [keyWindow.rootViewController topmostViewController];
  25.         //NSLog(@"PresentedViewController: %@", [presentedViewController class]);
  26.        
  27.         if ([self vcIsVideoPlayer:presentedViewController] ){
  28.             orientations = UIInterfaceOrientationMaskAll;
  29.         }
  30.         else{
  31.             if ([presentedViewController isKindOfClass:[UIActivityViewController class]] || [presentedViewController isKindOfClass:[UIAlertController class]]) {
  32.                 orientations = UIInterfaceOrientationMaskPortrait;
  33.             }
  34.             else{
  35.                 orientations = [presentedViewController supportedInterfaceOrientations];
  36.             }
  37.         }
  38.     }
  39.    
  40.     return orientations;
  41. }
  42.  
  43. - (BOOL)vcIsVideoPlayer:(UIViewController *)vc{
  44.     static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7   = @"MPInlineVideoFullscreenViewController";
  45.     static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8   = @"AVFullScreenViewController";
  46.     static NSString * const VIDEO_CONTROLLER_CLASS_NAME_NATIVE = @"MPMoviePlayerViewController";
  47.    
  48.     NSString *className = vc ? NSStringFromClass([vc class]) : nil;
  49.     return (
  50.             [className isEqualToString:VIDEO_CONTROLLER_CLASS_NAME_NATIVE] ||
  51.             [className isEqualToString:VIDEO_CONTROLLER_CLASS_NAME_IOS7] ||
  52.             [className isEqualToString:VIDEO_CONTROLLER_CLASS_NAME_IOS8]
  53.             );
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement