0

I'm encountering an issue while using a webview. My app is currently a portrait application, but when a media player loads in a webview within my app, the user can rotate the player, which rotates my view controller as well. I know I can get a notification for when the player comes up and disappears, but is there a way to prevent it from rotating the controller in the first place?

It doesn't seem like anyone has an answer. I have all of the standard "don't rotate unless if I tell you to" methods and plist values, but its still rotating. Its only when I load up a webview and the media player loads over it. If I rotate my device, the media player rotates along with it, which feels natural, but when I go back to the webview view controller, its rotated, which isn't good.

RileyE
  • 10,874
  • 13
  • 63
  • 106
  • I can't reproduce this behavior. A video player in a web view does not autorotate when the view controller that owns the web view forbids rotation. Tested on 4.3, 5.1 and 6.0 – Nikolai Ruhe Jul 02 '12 at 07:38
  • That doesn't make any sense. Have you tried loading up youTube with your device and make sure that your rotation lock is off? – RileyE Jul 02 '12 at 16:48
  • I believe your bug is elsewhere. Here's a test project to confirm: http://dl.dropbox.com/u/1296542/NoRot.zip – Nikolai Ruhe Jul 03 '12 at 07:50
  • @RileyE is your application tab based? – Mashhadi Jul 04 '12 at 10:04
  • No. Its UINavigationController based. – RileyE Jul 04 '12 at 18:05
  • @Mashhadi would that cause an issue? – RileyE Jul 04 '12 at 18:06
  • It is the issue. Why does it rotate when there is a navigation controller and when there isn't, it won't rotate? – RileyE Jul 04 '12 at 20:07
  • It doesn't metter that you have a navigation controller. If your controller is in Tabbar then it may cause this issue. – Mashhadi Jul 05 '12 at 09:04
  • It actually is also with a navigation controller. I've removed the controller and it prevented the issue. Its a stupid bug. – RileyE Jul 05 '12 at 15:40
  • I think this works fine with YouTube videos but other video sources show the issue. – nh32rg Jul 11 '12 at 16:33
  • @nh32rg What do you mean? I'm just curious, since I've only tried it with YouTube (the media player loads within my app, through the web view). – RileyE Jul 11 '12 at 19:26

3 Answers3

0

Add this key in your info.plist :

UISupportedInterfaceOrientations and set it to UIInterfaceOrientationPortrait

AJS
  • 1,403
  • 12
  • 17
0

Ok, this a blind shot. I've used this trick to force the system to adjust to the required orientation, add this lines when the webview will appears, or when the player will disappear:

UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];

Try in some of those methods, or in the didAppear or didDisappear if dosen't work. I know it look like rubbish, but sometimes works.

JP Illanes
  • 3,665
  • 39
  • 56
  • I know what you mean, but I'm hoping to avoid unnecessary processing. I could probably just force it by manually changing the device orientation. – RileyE Jun 30 '12 at 03:55
  • Yeah, it's a shame, but this kind of stuff is the only solutions for orientation issues in iOS, I've struggled with this a lot. – JP Illanes Jun 30 '12 at 03:59
  • But I'm sure that the is a solution. This is a very major issue! – RileyE Jun 30 '12 at 04:29
  • Apple is too big of a corporation to have this large of a bug. – RileyE Jun 30 '12 at 04:30
  • If you found it, let me know! As far as I know, there is no other way. (But, don't tell anybody - AKA NDA - they are completely changing the way orientations transitions works in iOS 6, so maybe there's your "solution") – JP Illanes Jun 30 '12 at 04:34
  • This is the solution, check my answer in another thread http://stackoverflow.com/questions/970482/uinavigationcontroller-and-autorotation/5347071#5347071 – xingzhi.sg Jul 03 '12 at 06:19
  • @xingzhi.sg The question is about preventing rotation—not about how to fix it. – Nikolai Ruhe Jul 03 '12 at 08:05
  • 1
    @NikolaiRuhe, unless we are Apple engineers. This is a known "bug" since iOS 3 at least and until Apple fix it we just try to live with it with our dirty fixes... – xingzhi.sg Jul 03 '12 at 08:48
  • 1
    Is it just me, or is this ridiculous? How can there be this big of an issue for so long? – RileyE Jul 05 '12 at 04:03
0

There doesn't seem to be a correct answer to this question.

RileyE
  • 10,874
  • 13
  • 63
  • 106