简体   繁体   English

在iOS8上未调用willRotateToInterfaceOrientation

[英]willRotateToInterfaceOrientation not called on iOS8

I'm using the VFR PDF viewer library in my app, where I present it thus: 我在我的应用程序中使用VFR PDF查看器库 ,因此在其中显示它:

ReaderDocument *document = [ReaderDocument withDocumentFilePath:pdfFile password:nil];
ReaderViewController *vc = [[ReaderViewController alloc] initWithReaderDocument:document];
[self.navigationController pushViewController:vc animated:YES];

If I run on iOS7, everything works fine. 如果我在iOS7上运行,则一切正常。

If I run my app on iOS8, the willRotateToInterfaceOrientation method in ReaderViewController never gets called, so when the device is rotated the document doesn't get reformatted correctly. 如果我在iOS8上运行我的应用程序,则不会调用ReaderViewController中的willRotateToInterfaceOrientation方法,因此,旋转设备时,文档将无法正确格式化。

However, if I run the demo app that comes with the library on iOS8, the willRotateToInterfaceOrientation in ReaderViewController does get called, which leads me to believe the library is ok, and I'm doing something wrong (or neglecting to do something) in my app. 但是,如果我在iOS8上运行该库随附的演示应用程序,则会调用ReaderViewController中的willRotateToInterfaceOrientation,这使我相信该库是可以的,并且我做错了(或忽略了做某事)应用程式。

I'm rather puzzled at this behaviour. 我对此行为感到困惑。 Why doesn't willRotateToInterfaceOrientation get called in my app on iOS8, but it does under the other variations? 为什么在iOS8上的我的应用程序中未调用willRotateToInterfaceOrientation,但在其他版本中却会调用它呢? How can I try to track this down? 我该如何追踪呢?

I finally managed to resolve my problem; 我终于设法解决了我的问题; here is what the issue was in case anyone else has the same problem. 如果其他人遇到相同的问题,这就是问题所在。

My ReaderViewController was being presented from a class that had implemented viewWillTransitionToSize:withTransitionCoordinator: , so the deprecated methods on child view controllers weren't being called. 我的ReaderViewController是从实现了viewWillTransitionToSize:withTransitionCoordinator:的类中呈现的,因此未调用子视图控制器上不推荐使用的方法。

Also in that implementation it wasn't calling 同样在该实现中,它没有调用

[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]

and so the viewWillTransitionToSize:withTransitionCoordinator: method of all child view controllers wasn't being called either. 因此所有子视图控制器的viewWillTransitionToSize:withTransitionCoordinator:方法也没有被调用。

The fix was to add a call to 解决方法是添加一个呼叫

[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]

into the parent VC's viewWillTransitionToSize:withTransitionCoordinator: method, subclass ReaderViewController , then add a viewWillTransitionToSize:withTransitionCoordinator: to my subclass to call the appropriate methods in ReaderViewController . 进入父VC的viewWillTransitionToSize:withTransitionCoordinator:方法,子类ReaderViewController ,然后将viewWillTransitionToSize:withTransitionCoordinator:添加到我的子类中,以在ReaderViewController调用适当的方法。

Simply because willRotateToInterfaceOrientation is no more called in iOS8, it is deprecated. 仅仅因为在willRotateToInterfaceOrientation中不再调用willRotateToInterfaceOrientation,所以已弃用它。

If the new rotation methods are not implemented, and a project is compiled with the iOS 8 SDK, the view controllers -will not receive calls- to the deprecated rotation methods. 如果未实现新的旋转方法,并且使用iOS 8 SDK编译了项目,则视图控制器-将不会收到对已弃用的旋转方法的调用-。

A similar question to yours can be found here 您可以在这里找到类似的问题

Citation of @mluisbrown : @mluisbrown的引用:

The rotation methods are deprecated in the iOS 8 SDK. 旋转方法已在iOS 8 SDK中弃用。 This will have no effect at all on apps built with the iOS 7 SDK, even running in iOS 8 and probably several future versions of iOS. 这对于使用iOS 7 SDK构建的应用程序完全没有影响,即使在iOS 8和可能的多个iOS将来版本中运行也是如此。

I struggled a bit with some kind of a similar problem to yours. 我为与您的类似问题感到困惑。 I tried following Apple recommendation to use viewWillTransitionToSize , which in my case did not solve my problem because this only gets triggered on changes from regular to compact for example an not on rotation. 我尝试遵循Apple的建议使用viewWillTransitionToSize ,在我的情况下,它不能解决我的问题,因为这仅在从常规更改为压缩时触发,例如在不旋转时触发。

viewWillTransitionToSize:withTransitionCoordinator: to make interface-based adjustments. viewWillTransitionToSize:withTransitionCoordinator:进行基于界面的调整。

Which is detailed in apple documentation 苹果文档中有详细说明

Also a video of WWDC 2014 explains this but I can't remember which video it was. WWDC 2014的视频也对此进行了解释,但我不记得是哪个视频。 Perhaps the one on What's new in Cocoa touch or the one on View Controller Advancements in iOS 8 . 也许是有关What's new in Cocoa touch还是有关View Controller Advancements in iOS 8

EDIT 编辑

Note that in my case viewWillTransitionToSize , as explained, was not called because I wasn't changing from regular to compact so there was no size transition, strictly speaking for Apple. 请注意,在我的情况下,未调用viewWillTransitionToSize ,因为我没有从常规更改为紧凑,因此没有尺寸转换,严格来说,对于苹果而言。

The only solution I fount was to handle this manually in the viewDidLayoutSubviews of the corresponding view controller. 我找到的唯一解决方案是在相应视图控制器的viewDidLayoutSubviews中手动处理此问题。

In my case I wanted to keep track of the top cell displayed in a tableview with autolayout. 就我而言,我想跟踪自动布局的表格视图中显示的顶部单元格。 As it wasn't tracked automatically by the system, I had to check that manually and scroll manually to the adequate cell on rotation. 由于系统没有自动跟踪它,因此我不得不手动检查并手动滚动到旋转的适当单元格。 That's why I did it that way. 这就是为什么我这样做的原因。 It's quite "heavy" but works in my case. 它相当“沉重”,但对我而言适用。

I would also be interested if anyone has an easier solution. 如果有人有更简单的解决方案,我也会感兴趣。

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

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