繁体   English   中英

旋转Ipad时动画视图过渡

[英]animate view transition when rotating 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”方法并在其中添加一些动画,但是我不确定如何编写代码。 我之前没有任何动画,所以我没有任何进展。 有人可以帮帮我,谢谢!

方法: willRotateToInterfaceOrientation:duration:刚好在用户界面开始旋转之前被调用,用于准备旋转视图-在过渡动画发生之前设置视图状态。

基本上,不需要覆盖此方法,除非您要在视图过渡动画期间禁用视图交互,停止媒体播放或暂时关闭昂贵的图形或实时更新。 动画块中不会调用此方法。

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

希望这能解决您的问题。

您可能不想手动修复图形的框架和坐标系,因为UIViewController实际上会相应地旋转其视图。

使用以下方法可以在主视图的框架更改时自动调整其大小:

corePlotContent.view.autoresizeMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

并在图形视图中使用layoutSubviews方法对图形进行任何本地更改。

性能的缺乏可能是由于旋转动画期间进行了大量绘制(旋转期间每一帧都重新绘制了图形)。 我建议您可以使用willRotateToInterfaceOrientation暂时禁用图形重绘,并在对didRotateFromInterfaceOrientation的调用中重新启用它。

您也可以将Instruments与CPU Profiler工具一起使用,以检测代码中的瓶颈。

希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM