Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 14    Views: 77

Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
08/31/13 07:30 AM (12 years ago)

Orientation lock - almost there

Hi everybody First off all thank you so much for your help so far. I'm finishing up my app, but I have a little detail that annoys me a bit, but don't know if theres a solution out there. I have the menu simple, MacImage Gallery and AT53 video plugin as my main plugins. My screens consist of a lot of screens (a list) from the menu simple which is joined with the two other plugins. What I wan't is that the screen is locked in portrait in the menu simple, the MacImage gallery is both and AT53 video is only landscape when you playback the video. I have managed so far to lock the menu simple in portrait and landscape/portrait in MacImage BUT when I press back from the Image gallery in landscape mode the menu simple is also in landscape until you turn the device to portrait and it locks again. Same thing with the AT53. Here's the code - app delegate. //supportedInterfaceOrientationsForWindow... -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"supportedInterfaceOrientationsForWindow %@", @""]]; //allow / dissallow rotations BOOL canRotate = FALSE; //appDelegate dryneedling101_appDelegate *appDelegate = (dryneedling101_appDelegate *)[[UIApplication sharedApplication] delegate]; if ([[BT_strings getStyleValueForScreen:self.rootApp.currentScreenData nameOfProperty:@"itemType" defaultValue:@""] isEqualToString:@"Mac_image_gallery"]){ canRotate = TRUE; }else{ if ([[BT_strings getStyleValueForScreen:self.rootApp.currentScreenData nameOfProperty:@"itemType" defaultValue:@""] isEqualToString:@"At53_video_player"]){ canRotate = TRUE; }else{ if([appDelegate.rootApp.rootDevice isIPad]){ canRotate = FALSE; }else{ //should we prevent rotations on small devices? if([appDelegate.rootApp.jsonVars objectForKey:@"allowRotation"]){ if([[appDelegate.rootApp.jsonVars objectForKey:@"allowRotation"] isEqualToString:@"largeDevicesOnly"]){ NSLog(@"%@", @"SHOULD NOT ROTATE"); canRotate = FALSE; }} } } } Any suggestions?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/01/13 07:49 PM (12 years ago)
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/01/13 11:00 PM (12 years ago)
I'll try it. Do you suggest to add it in the appdelegate file? So far I've tried numerous codes without effect, but I gladly give this a shot.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/01/13 11:10 PM (12 years ago)
I guess it would depend on the whole app. If you want the entire app to be in landscape, then someplace global like the appDelegate may be appropriate. I've used it locally in my plugins, to keep them portrait, while other screens I prefer to leave alone, so 'per plugin' is my known recourse. If it doesn't seem to work in the appDelegate, you may have to do it per plugin. Haven't tried... Cheers! -- Smug
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/02/13 09:15 AM (12 years ago)
Which piece of code do you use for your plugins to keep in portrait, and where do you put it?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/02/13 03:14 PM (12 years ago)
I put this in my plugin code. It's a method that should be placed outside of any other method in your plugin implementation (.m) file... - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation); } Cheers! -- Smug
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/05/13 04:01 AM (12 years ago)
I have now tried to put in the code above. It accepts the code with no error, but it still keeps rotating. I put the code in the menu list plugin, and tried inserting it before and after the dealloc. Depending on where I put the code, sometimes it doesn't recognize the shouautotorate part.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/05/13 04:48 AM (12 years ago)
The code that I posted should be 'standing alone' as it's own method, and should be placed in the plugin that you don't want to rotate. Not sure about its reaction with every screen, I've only used it in a couple of plugins that I modified. But the theory is that it should work almost everywhere... Cheers! -- Smug
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/05/13 05:05 AM (12 years ago)
I now tried to download a new ios project I put the code in the BT_screen_menuListSimple.m file just above the //dealloc It still rotates when I try run the simulator
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/05/13 05:42 AM (12 years ago)
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/06/13 08:16 AM (12 years ago)
Okay, so I used 5 hours to get here, which is something. I'm so close! What I changed is I added the following in BT_navigationController.m below @implementation -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } and in appDelegate.M //supportedInterfaceOrientationsForWindow... -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"supportedInterfaceOrientationsForWindow %@", @""]]; //allow / dissallow rotations BOOL canRotate = FALSE; //appDelegate dryneedling101_appDelegate *appDelegate = (dryneedling101_appDelegate *)[[UIApplication sharedApplication] delegate]; if ([[BT_strings getStyleValueForScreen:self.rootApp.currentScreenData nameOfProperty:@"itemType" defaultValue:@""] isEqualToString:@"Mac_image_gallery"]){ canRotate = TRUE; }else{ if ([[BT_strings getStyleValueForScreen:self.rootApp.currentScreenData nameOfProperty:@"itemType" defaultValue:@""] isEqualToString:@"At53_video_player"]){ canRotate = TRUE; }else{ if([appDelegate.rootApp.rootDevice isIPad]){ canRotate = FALSE; }else{ //should we prevent rotations on small devices? if([appDelegate.rootApp.jsonVars objectForKey:@"allowRotation"]){ if([[appDelegate.rootApp.jsonVars objectForKey:@"allowRotation"] isEqualToString:@"largeDevicesOnly"]){ NSLog(@"%@", @"SHOULD NOT ROTATE"); canRotate = FALSE; }}} } } //bitwise OR operator... NSUInteger mask = 0; mask |= UIInterfaceOrientationMaskPortrait; if(canRotate){ mask |= UIInterfaceOrientationMaskLandscapeLeft; mask |= UIInterfaceOrientationMaskLandscapeRight; mask |= UIInterfaceOrientationMaskPortraitUpsideDown; } return mask; } This in the BT_viewController.m //should rotate -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"shouldAutorotateToInterfaceOrientation %@", @""]]; //allow / dissallow rotations BOOL canRotate = TRUE; //appDelegate dryneedling101_appDelegate *appDelegate = (dryneedling101_appDelegate *)[[UIApplication sharedApplication] delegate]; if ([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"itemType" defaultValue:@""] isEqualToString:@"Mac_image_gallery"]){ canRotate = TRUE; }else{ if([appDelegate.rootApp.rootDevice isIPad]){ canRotate = TRUE; }else{ //should we prevent rotations on small devices? if([appDelegate.rootApp.jsonVars objectForKey:@"allowRotation"]){ if([[appDelegate.rootApp.jsonVars objectForKey:@"allowRotation"] isEqualToString:@"largeDevicesOnly"]){ canRotate = FALSE; }} } } //can it rotate? if(canRotate){ return YES; }else{ return (interfaceOrientation == UIInterfaceOrientationPortrait); } //we should not get here return YES; and the last thing is menu simple plugin just below @synthesize -(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } Here is a video of what I get - http://db.tt/n8gmo4lj Some of it seems to work when I press back the second time, but not the first time. Any ideas?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/06/13 03:51 PM (12 years ago)
I don't know if I would change things 'everywhere'. Usually you'll want to update the appDelegate for things 'globally', and the plugin code for things 'locally'. Cheers! -- Smug
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/08/13 03:35 AM (12 years ago)
So what are your suggestions regarding the code I've written in the post?
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
09/08/13 07:40 AM (12 years ago)
Greetings! Nice work on that code. This is tricky and is something I hope to be able to control by screen sometime. I think it makes sense but rotation in apps is something that only gets more complex having ipad views in the mix. I have not visited this in a bit, but I believe that I ultimately fixed this by modding some code in the BT_tabBarController.m I can see in your demo video you are using the tab bar which I was as well in the app I was working on to make this work. I think that was overridding the methods in the individual plug-in files. Open up that file and you should see the method to rotate in there you can mod and add some if/then iphone vs ipad views too.
 
Djdios
Lost but trying
Profile
Posts: 175
Reg: Mar 20, 2013
Valby, Denmark
3,550
like
09/08/13 08:17 AM (12 years ago)
ATRAIN53: I've tried a lot of things but can't find the right code to make this happen I don't know if a tweak of the code for the layout is a possibility since it says: //some screens need to re-build their layout...If a plugin has a method called //"layoutScreen" we trigger it everytime the device rotates. The plugin author can //create this method in the UIViewController (layoutScreen) if they need something to //happen after rotation occurs. Do you remember what you did? I only have to figure this orientation part out before I can publish my app and I've used so many hours so far and I can see taht I'm very close now but everything stands still right now.
 

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.