方向在模拟器上工作但不在ios7的设备上工作

时间:2014-07-23 07:21:48

标签: ios xcode uinavigationcontroller orientation

我看过同一个问题的多个副本。但它不支持我的原因。

我已经尝试了为导航控制器继承navigationController添加类别的子类,当我尝试所有这些方法时,应该为navigationcontroller和视图控制器调用shouldAutoRotate和supportedInterfaceOrientations,但设备只保留在纵向视图中。

#import "UINavigationController+Rotation.h"

@implementation UINavigationController (Rotation)
- (BOOL)shouldAutorotate {

BOOL result = self.topViewController.shouldAutorotate;

return result;
}

- (NSUInteger)supportedInterfaceOrientations {

NSUInteger result = self.topViewController.supportedInterfaceOrientations;

return result;
}

@end

有些事情我做错了吗?

1 个答案:

答案 0 :(得分:0)

将此方法称为viewdidload

-(void)rotateCameraView {
          [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
          [[NSNotificationCenter defaultCenter] addObserver: self selector:   @selector(deviceOrientationDidChange:) name:   
   UIDeviceOrientationDidChangeNotification object: nil];
          }

旋转设备时,此方法将自动调用

-(void)deviceOrientationDidChange:(NSNotification *)notification {   
    //Obtaining the current device orientation 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];     
    //Ignoring    specific orientations 
    if (orientation == UIDeviceOrientationFaceUp
    ||    orientation == UIDeviceOrientationFaceDown || orientation ==  
    UIDeviceOrientationUnknown) { return; } 
    if ((UIDeviceOrientationIsPortrait(orientation)   
    ||UIDeviceOrientationIsPortrait(orientation)) ||   
    (UIDeviceOrientationIsLandscape(orientation) ||   
    UIDeviceOrientationIsLandscape(orientation))) { 
    //still saving the  current orientation 
    currentOrientation = orientation; } [self   
    performSelector:@selector(orientationChangedMethod) withObject:nil  
    afterDelay:0]; 
}

-(void)orientationChangedMethod
{
   switch (currentOrientation) {

       case UIDeviceOrientationPortrait:

           if (isOrientationEffect==YES)
           {
               appDelegate.imagePickerController.cameraViewTransform = CGAffineTransformMakeRotation(M_PI);

                //                if (!isPurchased) 
                //                { 
                // 
                //                    [self buttonFrameWithIad]; 
                //             } 
                //                else 
                //                { 
                //                  [self buttonFrameWithoutIad]; 
                //                }

               [self MakeTransformRotation];
           }
           [UIView beginAnimations:@"rotateView" context:nil];
           [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
           [UIView setAnimationDuration:0.35f];

           camDefaultImg.transform = CGAffineTransformMakeRotation(0);
           [UIView commitAnimations];

           break;
       case UIDeviceOrientationLandscapeLeft:

           if (isOrientationEffect==YES)
           {
           } 
      }