旋转 Ipad 时动画视图过渡

发布于 2024-10-23 17:05:29 字数 955 浏览 1 评论 0原文

您好,提前感谢您的任何回复。

我有一个 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”方法并在那里添加一些动画,但我不确定如何编写代码。我之前没有制作过任何动画,所以我没有取得任何进展。有人可以帮帮我吗,谢谢!

Hi and thanks in advance for any responses.

I have an IPad app with two different views: one for portrait, one for landscape.
When I rotate the device, the transition between the views is not very smooth.I wanted to animate the transition between the two views so that it looks better.
This is what my code looks like for my rotation:

-(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);
    }
}

I think I need to override "willAnimateRotationToInterfaceOrientation" method and add some animation there but I'm not sure how to write the code. I haven't animated anything before so I'm not making any progress. Could someone please help me out, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久而酒知 2024-10-30 17:05:29

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

基本上,您不需要重写此方法,除非您想要禁用视图交互、停止媒体播放或在视图转换动画期间暂时关闭昂贵的绘制或实时更新。此方法不在动画块内调用

相反,您应该使用 willAnimateRotationToInterfaceOrientation:duration: 方法。此方法从用于旋转视图的动画块内调用 - 在此调用内所做的每个视觉属性更改都将被正确动画化。

希望这能解决您的问题。

The method: willRotateToInterfaceOrientation:duration: is called just before the user interface begins rotating, it's used to prepare view for rotation - to setup state of view before the transition animation occurred.

Basically, you do not need to override this method, unless you want to disable view interactions, stop media playback, or temporarily turn off expensive drawing or live updates during the view transition animation. This method is not called within the animation block.

Instead, you should use willAnimateRotationToInterfaceOrientation:duration: method. This method is called from within the animation block that is used to rotate the view - every visual property change made inside this call will be properly animated.

Hope this solves your problem.

×纯※雪 2024-10-30 17:05:29

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

使用类似的方法可以在主视图的框架发生变化时自动调整其大小:

corePlotContent.view.autoresizeMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

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

性能的缺乏可能来自于旋转动画期间的大量绘制(旋转期间的每一帧都会重新绘制图形)。我建议您可以使用 willRotateToInterfaceOrientation 暂时禁用图形的重绘,然后在调用 didRotateFromInterfaceOrientation 时重新启用它。

您还可以将 Instruments 与 CPU Profiler 工具结合使用来检测代码中的瓶颈。

希望有帮助。

You probably don't want to fix the frame and coordinate system of your graph by hand since the UIViewController actually rotates its view accordingly.

Use something like this to have it automatically resized when the frame of the main view changes:

corePlotContent.view.autoresizeMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

And use the layoutSubviews method in your graph view to do any local changes for the graph.

The lack of performance probably comes from extensive drawing during the rotation animation (the graph is redrawn for every frame during the rotation). I suggest you could use willRotateToInterfaceOrientation to disable redrawing of the graph for a moment and re-enable it in the call to didRotateFromInterfaceOrientation.

Also you can use Instruments with the CPU Profiler instrument to detect the bottleneck within your code.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文