2014-09-05 78 views
6

enter image description here我创建了视图旋转的类别,并在控制器视图以及窗口(用于显示自定义指标)上添加了视图。 我的代码在xCode 5.X以及xCode6-beta6中正常工作到7.X。但是IOS 8测试版不适合。 它似乎像Windows旋转不工作与ios 8测试版相同像老ios。ios 8添加到窗口的视图的旋转问题

您能否请我建议.... 非常感谢。

我的代码看起来像

- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration { 
if(!self.isIpad) 
{ 

    [menu.view rotateViewToOrientation:newStatusBarOrientation animated:YES]; 
    if(newStatusBarOrientation==UIInterfaceOrientationPortrait || newStatusBarOrientation==UIInterfaceOrientationPortraitUpsideDown) 
    { 
     if (IS_IPHONE_5) { 
      menu.view.frame= CGRectMake(0, 518, 320, 50); 
     } else { 
      menu.view.frame= CGRectMake(0, 430, 320, 50); 
     } 

    } else if(newStatusBarOrientation==UIInterfaceOrientationLandscapeLeft) { 

     if (IS_IPHONE_5) { 
      menu.view.frame= CGRectMake(270,0,50,568); 
     } else { 
      menu.view.frame= CGRectMake(270,0,50,480); 
     } 

    } else { 

     if (IS_IPHONE_5) { 
      menu.view.frame= CGRectMake(0,0,50,568); 
     } else { 
      menu.view.frame= CGRectMake(0,0,50,480); 
     } 
    } 
    [menu reloadMenu]; 
    } 
} 


//Method of Menu Class for orientation change setup 
- (void)rotateViewToOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated { 
CGPoint center = self.center; 
CGRect bounds = self.bounds; 
CGAffineTransform transform = CGAffineTransformIdentity; 
int intOri=orientation; 
switch (intOri) { 
    case UIInterfaceOrientationPortraitUpsideDown: 
     transform = CGAffineTransformMakeRotation(M_PI); 
     break; 
    case UIInterfaceOrientationLandscapeLeft: 
     transform = CGAffineTransformMakeRotation(-M_PI_2); 
     break; 
    case UIInterfaceOrientationLandscapeRight: 
     transform = CGAffineTransformMakeRotation(M_PI_2); 
     break; 
    case UIInterfaceOrientationPortrait: 
     transform = CGAffineTransformMakeRotation(0); 
     break; 

} 
if (animated) { 
    [UIView beginAnimations:nil context:nil]; 
} 
self.transform = transform; 
bounds = CGRectApplyAffineTransform(bounds, transform); 
self.bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height); 
self.center = center; 
if (animated) { 
    [UIView commitAnimations]; 
} 
} 
+0

粘贴一些代码,并告诉你如何获得的问题,有什么功能不调用,否则任何事情? – Jageen 2014-09-05 11:42:13

+0

一般来说,大多数开发人员不知道如何构建适当的视图层次结构,这可能是问题的根源 - 您能否发布一些关于如何构建您的代码的代码? – holex 2014-09-05 11:54:31

+0

@Jageen我已经添加了我的代码,您能否以任何方式给我建议,我应该如何使我的应用程序兼容ios 8。 – 2014-09-05 12:21:26

回答

7

我已经尝试了很多修正...及其补丁那样工作

{ 
[self.window setBounds:temp]; 
[menu.view setFrame:CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50)]; 
[menu.view removeFromSuperview]; 
[self.window addSubview:menu.view]; 
[self.window makeKeyAndVisible]; 
} 

,并正在重置角度为0度CGAffineTransformMakeRotation所有类型对于ios 8.

这不是我知道的一个合适的解决方案,但我没有任何替代方式,所以等待一个很好的答案。

+0

你摇摆的人。 :) – NaXir 2014-10-27 08:11:53

+0

你把这个代码放在哪里? – ahalls 2014-10-27 19:23:53

4

在我的情况下,只需将所有方向的旋转角度设置为0即可解决问题。在iOS 8之前,UIWindow坐标始终处于纵向,因此您必须自己处理旋转。这在iOS 8中不再是必需的了。至于为什么要将UIViews添加到UIWindow中,我这样做是为了在不考虑当前视图层次结构的情况下显示在其他所有内容上的警报。

1

有类似的问题。令人惊讶的是,解决方法是在Appdelegate上注释与self.window相关的所有代码。

评论初始化self.window及其赋值。通过选中“初始视图控制器”复选框,在“属性”检查器中的故事板中设置初始视图。

新的更好的解决方案
谈到self.window是造成其他问题。相反,下面的代码是最好的:

- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification 
    { 
     [UIViewController attemptRotationToDeviceOrientation]; 
    }