Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 6    Views: 63

Sherry
Lost but trying
Profile
Posts: 135
Reg: Jan 05, 2013
South Africa
11,650
03/06/15 02:35 PM (9 years ago)

Rotate one plugin only on iphone and android phone

I am setting up an app for iphone and android phones using a tabbed layout and have the control panel set to only allow rotations on large devices because I want the majority of the app to be fixed in portrait view only. I have one exception however, the app has pdf files using the PDF Doc plugin and I want these screens to be able to rotate because they are sized for landscape view and when I tried to talk my client into accepting pdf files where I had manually rotated them 90º before adding to app he wasn't happy. I saw a post from a year ago where Kittsy had a fix for Video player but it doesn't work anymore so would really appreciate a step by step fix for both ios and android.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
03/06/15 02:43 PM (9 years ago)
I have tried to find something this week but could not get a perfect solution either. We may need Kittsy to revisit the solution for BT 3?
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
03/07/15 03:32 AM (9 years ago)
Nothing really ever worked for android as far as I know but this works for iOS: Don't remember who posted this, probably Chris or Kittsy: BT Rotation fixes for 3.0   This is to lock some screens in portrait and allow other screens to rotate…   Basically this method will remove the existing BT Rotation code (that doesn’t work according to David) and allow every screen to rotate now in your app via standard iOS methods.  The setting in your CP will no longer function after these hacks.   I based this off this great post here: http://b2cloud.com.au/how-to-guides/forcing-uiviewcontroller-orientation   The sample project there is the only one I've found that rotates the way I expected. I looked at all the SO posts and other tutorials. Some work, some don't and this one did as expected on all orientations and it uses XIB's.   The majority of posts with methods that work all suggest subclassing a navcontroller. I figured since the BT Nav controller is subclassed, this would fit right in and work with BT code.     Step 1   1) comment out all the rotation code in the BT_appdelegate code starting at @line 920   and replace it with this:   - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  // iOS 6 autorotation fix {     return UIInterfaceOrientationMaskAll;     }     Step 2 Comment out all the rotation code in the BT_viewController.m starting at @ line 1480     Step 3 Now set the supported orientations in Xcode General settings. By checking Portarit, landscape left, landscape right and upside-down too.   Now were controlling rotation thru Xcode.     Step 4   Now open the BT_navController.m and add this code to the bottom: (right before dealloc)   - (BOOL)shouldAutorotate {     return self.topViewController.shouldAutorotate; } - (NSUInteger)supportedInterfaceOrientations {     return self.topViewController.supportedInterfaceOrientations; }       Now you drop this code into screens you want to lock in PORTRAIT mode - for example the CR_menu advanced or maybe the BTA design menu…   Paste this code in the bottom somewhere right before the dealloc in the .m file of your screen.     ////drop in to lock screen in PORTRAIT:   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {     // Return YES for supported orientations     return (interfaceOrientation == UIInterfaceOrientationPortrait); }   - (BOOL)shouldAutorotate  // iOS 6 autorotation fix {     return YES; }   - (NSUInteger)supportedInterfaceOrientations // iOS 6 autorotation fix {     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {         return UIInterfaceOrientationMaskPortrait;     } else {         return UIInterfaceOrientationMaskAll;     } }   - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation // iOS 6 autorotation fix {     return UIInterfaceOrientationPortrait; }       and then drop this code in screens you want to allow to rotate:     //drop in to allow this screen to rotate   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {     return YES; }   - (BOOL)shouldAutorotate  // iOS 6 autorotation fix {     return YES; }   - (NSUInteger)supportedInterfaceOrientations // iOS 6 autorotation fix {     return UIInterfaceOrientationMaskAll; }   - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation // iOS 6 autorotation fix {     return UIInterfaceOrientationLandscapeLeft; }       That's it. You'll need to use the code snippets above to control and limit rotation now per screen.       Using a Tab Bar app?   Then you need to add these:   1) open BT_tabBarController.h declare these methods:   -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations;     2) open the BT_tabBarController.m   comment out everything after ViewDidLoad, none of this BT code is necessary.   Then drop this in the bottom before the @end:   - (BOOL)shouldAutorotate {     return [self.selectedViewController shouldAutorotate]; }   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {     return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; }   - (NSUInteger)supportedInterfaceOrientations {     return [self.selectedViewController supportedInterfaceOrientations]; }      
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
03/07/15 06:38 AM (9 years ago)
Thanks LeonG, I for one will try it out. I found an Android thread on the same thing, I don't know if it works though. http://www.buzztouch.com/forum/thread.php?tid=AE0B1A40BCED1E300772DB7&currentPage=1 FYI, the code I had previously tried was IOS for BT2.0. https://www.buzztouch.com/forum/thread.php?tid=03973855A4B0B0A764E7274&sortColumn=FT.id&sortUpDown=DESC&currentPage=1 It nearly worked. The problem was if I was in the landscape screen and then backed out of it, the screen that I came from would stay in landscape instead of flipping back into portrait. I will give this a go next week. Cheers, Alan
 
Sherry
Lost but trying
Profile
Posts: 135
Reg: Jan 05, 2013
South Africa
11,650
like
03/07/15 07:01 AM (9 years ago)
WHOO HOO LeonG you are my HERO!!! Thank you so so much for your help it works perfectly.
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
03/07/15 07:07 AM (9 years ago)
not my code, just keeping all snippets together in my growing collection ;-) Glad it helped though :-)
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
03/08/15 05:15 AM (9 years ago)
Thanks for sharing this Leon. I was quite excited to try this and I think it works really really well. It is a very clean solution and I like the way it respects the xcode rotation settings. I have done a little testing and the problem with the other fix, e.g. when you back out of a screen you can be in the wrong orientation is not a problem. Definately a keeper. I even think this is better than the existing buzztouch approach and perhaps should adopted as part of the core. There is one scenario that I wanted to do that I haven't suceeded in. I want one screen to start up in landscape (e.g. for recording video), when naviated to from a portrait menu. In my test, I start from a cr advanced menu, the screen I want starts in portrait (because I am holding the phone that way). I can rotate my phone to landscape and the screen rotates, then if I rotate again, that screen does not go back to portrait, which is fine. I just want that one screen to start in landscape. Any suggestions? Cheers, Alan
 

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.