willRotateToInterfaceOrientation not called on iOS8
Asked Answered
C

2

9

I'm using the VFR PDF viewer library in my app, where I present it thus:

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.

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.

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.

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? How can I try to track this down?

Cameral answered 10/11, 2014 at 10:6 Comment(0)
C
12

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.

Cameral answered 12/11, 2014 at 9:35 Comment(1)
As you manage to solve your problem, you can validate your own answer as the accepted answer so others know it is solved.Misdemeanant
M
3

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.

Misdemeanant answered 10/11, 2014 at 10:10 Comment(5)
I added a viewWillTransitionToSize:withTransitionCoordinator: method to the ReaderViewController class, and that isn't called upon device rotation either. Do I need to do anything in addition to adding that method?Cameral
A rotation is not exactly a size transition. Apple assume it is one in case you go from a compact to regular size in landscape or portrait. In my case to detect the rotation I had to handle the behavior manually in the viewDidAppear of the specified controller. Unfortunately I did not find any other easy was to do it.Misdemeanant
Now I'm even more confused! viewDidAppear is only called when the view appears, not when the device is rotated, so I don't understand how you handle the behaviour there.Cameral
Sorry i did not remember correctly. I had to use viewDidLayoutSubviews to have it working properly. As you are stating, viewDidAppear is only called once.Misdemeanant
Another point. When you tried viewWillTransitionToSize did you try it in the appdelegate or directly in the viewcontroller. Because I see in my code that I also use viewWillTransitionToSize in my viewController. I assume that it is to handle a size change but the rotation is handled by the viewDidLayoutSubviewsMisdemeanant

© 2022 - 2024 — McMap. All rights reserved.