2011-03-17 94 views
0

嗨,并提前感谢任何答复。旋转Ipad时动画视图过渡

我有一个iPad应用程序与两个不同的意见:一个肖像,一个景观。 当我旋转设备时,视图之间的转换不是很流畅。我想动画两个视图之间的转换,以便它看起来更好。 这是我的代码看起来像我的旋转:

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

[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     self.view = corePlotContent.view; //make graph the landscape view 
     self.view.transform = CGAffineTransformMakeRotation(deg2rad*(-360)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0); 
    }else{ 
     self.view = portraitView; 
     self.view.transform = CGAffineTransformMakeRotation(0); 
     self.view.bounds = CGRectMake(0.0, 0.0, 768.0, 1004.0); 
    } 
} 

我想我需要重写“willAnimateRotationToInterfaceOrientation”方法,并添加一些动画有,但我不知道如何编写代码。我之前没有动画,所以我没有取得任何进展。有人可以帮助我,谢谢!

回答

1

你可能不想要固定框架,并用手协调您的图形系统,因为实际的UIViewController相应地旋转视图。

使用这样的事情有当主视图变化框架,它会自动调整大小:

corePlotContent.view.autoresizeMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

,并使用layoutSubviews方法在你的图形视图做图的修改。

缺乏性能旋转动画(曲线图中的旋转过程中重新绘制为每帧)期间可能来自广泛图。我建议你可以使用willRotateToInterfaceOrientation禁用图形重绘了一会儿,在呼叫重新启用它didRotateFromInterfaceOrientation

此外,您还可以使用仪器与CPU Profiler仪器来检测代码中的瓶颈。

希望有所帮助。

+0

感谢您的建议。我只是想知道如果我只是通过动画可以使转换更平滑,因为当横向视图弹出时,我会看到一些空白区域。 – serge2487 2011-03-17 20:24:14

3

的方法:willRotateToInterfaceOrientation:duration:被调用之前的用户界面开始旋转时,它被用来对旋转准备视图 - 到的视图设置状态发生过渡动画之前。

基本上,你不需要重写此方法,除非你想关闭视图相互作用,阻止媒体播放,或暂时视图转变动画期间关闭昂贵的图纸或实时更新。该方法是在动画块内未调用的

相反,你应该使用willAnimateRotationToInterfaceOrientation:duration:方法。在用于旋转视图的动画块中调用此方法- 在此调用中进行的每个视觉属性更改都将进行适当的动画处理。

希望这可以解决您的问题。

+0

伟大的技巧 - 谢谢你。为我节省了大量不必要的工作。 – 2012-08-19 03:49:30