Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 95

fusionsch
I hate code!
Profile
Posts: 516
Reg: Dec 28, 2010
Montreux Switze...
11,610
03/09/13 08:30 AM (12 years ago)

How to prevent landscape orientation on iPad?

I've read many things about this in the forum (and tried a few of the tweaks) but after the March 3 update I guess things have changed a bit? On iPad (running any iOS, not only 6) I wish to have only portrait mode (no landscape ever), without preventing change of orientation when turning the device upside down. If anybody can provide a method, you're welcome! And if you have a feedback about Apple's approval/refusal of such a 'blocked' orientation app, you're welcome too! Thanks in advance Jack
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
03/09/13 09:08 AM (12 years ago)
Hi @fisionsch, Try this code: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight); }
 
fusionsch
I hate code!
Profile
Posts: 516
Reg: Dec 28, 2010
Montreux Switze...
11,610
like
03/09/13 12:35 PM (12 years ago)
Hi! Thanks, but... where? I see that 'shouldAutorotateToInterfaceOrientation' reference in BT_viewController.m, is it there I should edit the code? How exactly? Cheers Jack
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
03/09/13 12:48 PM (12 years ago)
Hi @fusionch, I believe so yes. I'm not for sure because I mostly do Android. Scroll down until you find that code but it will say portrait instead of landscape but everything else should match. Then you can change it to landscape or try to copy the code and paste over the found code in the m. file. LA
 
Frogman
Aspiring developer
Profile
Posts: 264
Reg: Jan 05, 2013
Bratislava
11,190
like
03/09/13 01:01 PM (12 years ago)
Gang, what about adding an option to prevent rotation on large devices too? Cheers, Frogman
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
03/09/13 01:08 PM (12 years ago)
Not sure @Frogman. He's using an IPad so that would be a large device, correct? I am winging it here with some research. If you know how, please jump in. LA
 
Frogman
Aspiring developer
Profile
Posts: 264
Reg: Jan 05, 2013
Bratislava
11,190
like
03/09/13 03:59 PM (12 years ago)
LA, this was more an item for the wishlist @BT_gang, testing if David @ Buzztouch can hear our voices :) Yes, we can prevent rotation at small device but not at a large device I think. I will check, but I am afraid that with my very limited knowledge I would be just pretending :( So this is what the wisdom says: Lots of apps look and perform better when only portrait orientation is supported. You cannot turn off landscape orientation for large devices (tablets). All tablets support both orientations. Frogman
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/09/13 10:24 PM (12 years ago)
Yes, you can prevent rotation on the iPad @fusionsch - here is how to do exactly what you asked (only allow portrait orientations) - Basically, to completely disable iPad rotation, all you have to do is type "canRotate" (without the quotations) into the Xcode search box - you should come up with around 12 results Replace every occurrence of 'TRUE' with 'FALSE' on every single one of those results, and rotation should be completely disabled Now, to get it to still rotate to the upside-down portrait orientation, you will need to paste this block of code into each individual screens .m file that is used in your app - paste it way at the top, right underneath the '@synthesize' statements - - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); } I think that should do it - there may be other ways, but that's how I would go about doing it
 
fusionsch
I hate code!
Profile
Posts: 516
Reg: Dec 28, 2010
Montreux Switze...
11,610
like
03/10/13 12:47 AM (12 years ago)
Thanks a lot, Absentia, I'm currently trying, but your method is incomplete! First part is ok, replacing every occurrence of 'TRUE' with 'FALSE' blocks rotation. But something is missing in the second part, as there is an exception to the trick: on BT_viewController.m there is already a 'shouldAutorotateToInterfaceOrientation' around line 325. So pasting a duplicate declaration underneath '@synthesize' brings an error message... Do you know how to edit the declaration around line 325? I'm not enough into code to do it without messing up everything ;-) Thanks in advance! Jack
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/10/13 12:51 AM (12 years ago)
No, you don't need to paste the code in BT_viewController - I guess I should have been more clear You need to paste that code into each screens .m file that is being used in your app. For example, if your app uses a button menu, image menu, quiz, and html screen, then you would paste the code into each of those screens .m files
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
03/10/13 07:21 AM (12 years ago)
Hey gang, I tried..lol I think I was a little off. Thank you @Frogman and @Absentia. LA
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.