willRotateToInterfaceOrientation not called on iOS8

别说谁变了你拦得住时间么 提交于 2019-12-03 13:15:19
Dave W

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.

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.

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.

HpTerm

Simply because willRotateToInterfaceOrientation is no more called in iOS8, it is deprecated.

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.

A similar question to yours can be found here

Citation of @mluisbrown :

The rotation methods are deprecated in the 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.

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.

viewWillTransitionToSize:withTransitionCoordinator: to make interface-based adjustments.

Which is detailed in apple documentation

Also a video of WWDC 2014 explains this but I can't remember which video it was. Perhaps the one on What's new in Cocoa touch or the one on 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.

The only solution I fount was to handle this manually in the viewDidLayoutSubviews of the corresponding view controller.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!