如何捕获当前视图屏幕截图并在代码中重用?(iPhone SDK)

How to capture current view screenshot and reuse in code? (iPhone SDK)(如何捕获当前视图屏幕截图并在代码中重用?(iPhone SDK))

本文介绍了如何捕获当前视图屏幕截图并在代码中重用?(iPhone SDK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户旋转设备时,我正在尝试从一个 UIView 转换到另一个.这本身并不难.但是,由于我在旋转后显示的是完全不同的内容,所以 UIKit 提供的默认动画(旋转当前显示的视图)在概念上是不合适的.

I am attemting to transition from one UIView to another, when the user rotates the device. This, in of itself, is not difficult. However, since I am displaying completely different content after the rotation, the default animation provided by UIKit (rotating the currently displayed view) is inappropriate conceptually.

简单地禁用动画并突然交换视图是可以容忍的,但远低于我正在构建到应用程序其余部分的润色.我更愿意这样做:

Simply disabling the animation and swapping the views suddenly is tolerable, but is far below the polish I'm building into the rest of the app. What I would prefer to do is this:

当调用 shouldAutorotateToInterfaceOrientation: 时,我想获取旋转前用户视图的不透明视图快照,如果你愿意,可以截屏.然后在旋转完成并且系统应用了视图变换等之后,我可以显示我保存的快照视图并将我选择的动画转换为我的新视图.完成后,我可以释放我的快照并继续前进.

When shouldAutorotateToInterfaceOrientation: is called, I would like to grab an opaque view snapshot, a screenshot if you will, of the user view before rotation. Then after the rotation is completed and the system has applied the view transforms etc, I can show the snapshot view I saved and animate a transition of my choice to my new view. After it is completed, I can release my snapshot and move on.

有没有不花钱的方法?

我能想到的唯一其他选择是在除默认方向之外的所有方向上都返回 NO,然后通过应用我自己的动画和变换来做出反应.但是,我更喜欢使用系统来执行此操作,因为我觉得自己执行此操作可能会导致手动旋转视图中的未定义"键盘行为等.

The only other option I can think of is to return NO on all orientations other than my default one, and then react by applying my own animations and transforms. I'd prefer to use the system to do this however, as I feel it is likely doing it myself could cause "undefined" keyboard behavior in the manually rotated view, etc.

想法?

推荐答案

我可以保证 [window drawRect:] 不会工作.大多数视图没有实现 drawRect: 并且它肯定不像在 mac 上那样递归.

I can guarantee you [window drawRect:] won't work. Most views don't implement drawRect: and it's certainly not recursive like on the mac.

drawInContext: 也非常相似,因为它从根本上要求图层绘制自己,而不是递归地绘制它的子图层.默认实现什么都不做."说明一切.

drawInContext: is also pretty much hosed simalarly, as it's fundamentally asking the layer to draw itself, not its sublayers recursively. "Default implementation does nothing." says it all.

我通过执行以下操作在应用商店中为 Clif Bar Save Our Snow 应用实现此功能:

I implementing this for the Clif Bar Save Our Snow app in the app store by doing the following:

  • 递归遍历层级,从每一层获取内容.如果它闻起来像图像,请使用 CGContext 方法将其绘制到您的上下文中.
  • 在行走时,请确保在递归调用时应用每一层的变换/位置

是的,相当大的痛苦.但是,是的,它运行得很好,并且被 Apple 解决了 :).

Yes, a rather large pain in the ass. But yes, it works pretty well and got through by Apple :).

这篇关于如何捕获当前视图屏幕截图并在代码中重用?(iPhone SDK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何捕获当前视图屏幕截图并在代码中重用?(iPhone SDK)

基础教程推荐