objective-c iPhone 应用程序的单阶段与两阶段动画?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2048781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:45:01  来源:igfitidea点击:

Single-Stage vs Two-Stage Animation for iPhone Apps?

iphoneobjective-canimationrotation

提问by Devoted

What are single-state and two-stage animation for rotating an iPhone window?

什么是用于旋转 iPhone 窗口的单状态和两阶段动画?

This is the "error" message I get in the Debugger Console (nothing crashes):

这是我在调试器控制台中收到的“错误”消息(没有崩溃):

Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.

I was working through the book "Beginning iPhone Development: Exploring the iPhone SDK" by Apress (Dave Mark, Jeff LaMarche) on the Swap Project.

我正在阅读 Apress(Dave Mark、Jeff LaMarche)关于 Swap 项目的“开始 iPhone 开发:探索 iPhone SDK”一书。

采纳答案by Ed Marty

Everything is explained in the UIViewController Class Reference. Especially check out the View Rotationsection near the top.

UIViewController 类参考中解释了所有内容。尤其要查看顶部附近的“视图旋转”部分。

From the reference:

从参考:

Handling View Rotations

By default, the UIViewController class displays views in portrait mode only. To support additional orientations, you must override the shouldAutorotateToInterfaceOrientation:method and return YES for any orientations your subclass supports. If the autoresizing properties of your views are configured correctly, that may be all you have to do. However, the UIViewController class provides additional hooks for you to implement additional behaviors as needed.

To temporarily turn off features that are not needed or might otherwise cause problems during the orientation change, you can override the willRotateToInterfaceOrientation:duration:method and perform the needed actions there. You can then override the didRotateFromInterfaceOrientation:method and use it to reenable those features once the orientation change is complete.

If you want to perform custom animations during an orientation change, you can do so in one of two ways. Orientation changes used to occur in two steps, with notifications occurring at the beginning, middle, and end points of the rotation. However, in iPhone OS 3.0, support was added for performing orientation changes in one step. Using a one-step orientation change tends to be faster than the older two-step process and is generally recommended for any new code.

To add animations for a one-step orientation change, override the willAnimateRotationToInterfaceOrientation:duration:method and perform your animations there. To use the older two-step method, override one or both of the willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:and willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:methods to configure your animations before each step. You must choose only one technique and override just the methods associated with that technique. If you override either method associated with the two-step technique, the view controller uses that technique by default.

处理视图旋转

默认情况下, UIViewController 类仅以纵向模式显示视图。要支持其他方向,您必须覆盖该 shouldAutorotateToInterfaceOrientation:方法并为您的子类支持的任何方向返回 YES。如果您的视图的自动调整大小属性配置正确,这可能就是您所要做的。但是, UIViewController 类为您提供了额外的钩子来根据需要实现额外的行为。

要暂时关闭不需要的特征或在方向更改期间可能会导致问题的特征,您可以覆盖该 willRotateToInterfaceOrientation:duration:方法并在那里执行所需的操作。然后,您可以覆盖该 didRotateFromInterfaceOrientation:方法并在方向更改完成后使用它重新启用这些功能。

如果要在方向更改期间执行自定义动画,可以通过以下两种方式之一进行。方向更改过去分两步发生,通知发生在旋转的开始、中间和结束点。但是,在 iPhone OS 3.0 中,添加了对一步执行方向更改的支持。使用一步方向更改往往比旧的两步过程更快,并且通常建议用于任何新代码。

要为一步方向更改添加动画,请覆盖该 willAnimateRotationToInterfaceOrientation:duration:方法并在那里执行动画。要使用旧的两步法, 请在每一步之前覆盖willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:方法中的一个或两个 以配置动画。您必须只选择一种技术并仅覆盖与该技术相关的方法。如果您覆盖与两步技术关联的任一方法,则视图控制器默认使用该技术。

回答by Vish

I changed from willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:method to willAnimateRotationToInterfaceOrientation:duration:method and warning gone.

我从willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:方法到willAnimateRotationToInterfaceOrientation:duration:方法和警告消失了。

Thanks.

谢谢。

回答by knaught

I have found the culprit in my case to be the UIImagePickerController (I also do not override any rotation animation):

在我的案例中,我发现罪魁祸首是 UIImagePickerController(我也没有覆盖任何旋转动画):

[self presentModalViewController:imagePicker animated:YES];

[self presentModalViewController:imagePicker 动画:YES];

Replacing imagePicker with a generic UIViewController doesn't generate any warnings.

用通用 UIViewController 替换 imagePicker 不会产生任何警告。

回答by jasontwong

If you're using iOS 4 and you're getting this warning, I found a way to get rid of it. In your info.plist, there is an item called "Supported interface orientations." Select which orientations your application supports and two-stage warnings will go away when bringing up the imagePicker.

如果您使用的是 iOS 4 并且收到此警告,我找到了摆脱它的方法。在您的 info.plist 中,有一个名为“支持的界面方向”的项目。选择您的应用程序支持哪些方向,当打开 imagePicker 时两阶段警告将消失。

回答by Rob

@plumiscles answer didn't quite work for me - there was no item called 'Supported Interface Orientations', probably b/c it is an old project. But you can get the same effect by editing the .plist file directly and adding this:

@plumiscles 的回答对我来说不太适用 - 没有名为“支持的接口方向”的项目,可能 b/c 这是一个旧项目。但是你可以通过直接编辑 .plist 文件并添加以下内容来获得相同的效果:

 <key>UIInterfaceOrientation</key>
  <string>UIInterfaceOrientationPortrait</string>

回答by user385662

Ed Marty's answer is the correct one. The reason it will happen if you are not overriding any of the rotation animation is probably that you reply "YES" to shouldAutorotate.. for some view. If you do not implement rotation at all, then you should just not override the shouldAutorotate.. method. If you do override that method, then just override the single step rotation method as well and pass it along to the super.

埃德马蒂的答案是正确的。如果您没有覆盖任何旋转动画,它会发生的原因可能是您对 shouldAutorotate.. 回复“YES”以获取某些视图。如果您根本不实现旋转,那么您不应该覆盖 shouldAutorotate.. 方法。如果您确实覆盖了该方法,那么也只需覆盖单步旋转方法并将其传递给超级。

回答by Jigar

Need to add UIImagePickerControlleras a subview to solve this error

需要添加UIImagePickerController子视图来解决这个错误

[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:NO];

回答by chrisben

I've had this issue after creating a tabbarcontroller with no view controllers inside (no tabs), this warning disappeared once I attached at least one view controller to it.

在创建了一个内部没有视图控制器(没有选项卡)的 tabbarcontroller 后,我遇到了这个问题,一旦我将至少一个视图控制器附加到它,这个警告就消失了。

回答by beryllium

I've delete from plist "Supported interface orientations" row and warning disappears.

我已从 plist “支持的界面方向”行中删除,警告消失。

回答by Juan González

I just had the same problem. In my case was a silly mistake that I'm putting here just in case anyone else falls into that same issue.

我只是遇到了同样的问题。就我而言,这是一个愚蠢的错误,我把它放在这里以防其他人遇到同样的问题。

In my tabbed app I remove one of the original ViewControllers and added a new one with Storyboard to create a "Settings" section.

在我的选项卡式应用程序中,我删除了一个原始 ViewControllers 并添加了一个带有 Storyboard 的新 ViewController 以创建一个“设置”部分。

This new VC had to be a table view VC and even I designed, compiled and run it without a problem, when I changed the orientation of the app I kept getting this “Using two-stage rotation animation” error.

这个新的 VC 必须是一个表视图 VC,即使我设计、编译和运行它也没有问题,当我改变应用程序的方向时,我不断收到“使用两阶段旋转动画”错误。

My problem was that I forgot to change in the original .h file interface "UIViewController" for "UITableViewController".

我的问题是我忘记在“UITableViewController”的原始 .h 文件界面“UIViewController”中进行更改。

Once this was done I changed on the Storyboard identity badge the class from the general value to my SettingsViewController and that was the end of it.

完成此操作后,我将 Storyboard 标识徽章上的类从一般值更改为我的 SettingsViewController,这就是它的结束。

I hope it can help someone else. It took me a while to get to bottom of this.

我希望它可以帮助别人。我花了一段时间才弄清楚这件事。

Cheers,

干杯,