iOS6和iOS5中UIImage方向的不同行为

时间:2012-12-27 12:19:04

标签: iphone objective-c ios uiimageorientation

我创建了一个只有纵向的iphone应用程序,即使我在旋转设备的同时制作了一个支持横向的视图 在iOS6中一切正常但是当我在iOS5上运行时,横向模式不正确它会显示一些讨厌的图像。 (两款设备均为ipod 3.5“视网膜显示器)

为什么会这样?

在此处添加我的代码和屏幕截图

在iOS6中 first view After rotating the device iOS 5中的

first view After rotating the device         - (void)viewDidLoad {     [super viewDidLoad];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotate:)
                                               name:UIDeviceOrientationDidChangeNotification
                                           object:nil];


}



- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[notification object] orientation];

if (orientation == UIDeviceOrientationLandscapeLeft) {
    [self.grpView setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
   imageScrollView.frame =CGRectMake(-50, -100, 400, 620);



} else if (orientation == UIDeviceOrientationLandscapeRight) {
    [self.grpView setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
    [self.grpView setTransform:CGAffineTransformMakeRotation(M_PI)];
} else if (orientation == UIDeviceOrientationPortrait) {
    [self.grpView setTransform:CGAffineTransformMakeRotation(0.0)];

}
}

1 个答案:

答案 0 :(得分:1)

在ios6中不推荐使用InterfaceOrientation方法。 因此,如果您希望ios5& ios6,你必须为ios6和

编写两个额外的方法
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// your customisation will go here
}

ios6的两个额外方法

    - (BOOL)shouldAutorotate
    {
        return YES;
    }

    - (NSUInteger)supportedInterfaceOrientations
       {
   // your customisation will go here
       }

享受编程!