Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 12    Views: 116

chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
01/05/13 07:07 AM (12 years ago)

2 questions about iOS programming

Okay, here's a longshot. I have 2 questions about iOS programming that are driving me nuts! 1) Is it possible to prevent rotation for a plugin despite what the overall settings are in XCode? Since BT uses only one viewcontroller file, I can't use any of the solutions found online that I've seen so far. Really I need it to rotate back to portrait view when device is rotated otherwise, which will mimic non rotation of the screen. 2). If I have a UITextfield on a tableview, how can I move the screen up on keyboard display assuming the textfield gets hidden? The Apple doc suggestion involves passing the active field reference to the keyboarddidshow event listener. But the way current BT menus are setup, cell configuration and subsequent UI element creation is done in a separate class file, so I'm having a hard time passing reference back to the parent class at the listener event. Hope someone can help! Thanks
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/05/13 08:42 AM (12 years ago)
okay - ignore the 2nd question - I think I figured that one out.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/05/13 09:43 AM (12 years ago)
Okay here is a hack for the rotation problem In your appDelegate.m comment out like below about line 975 //supportedInterfaceOrientations is needed for iOS 6 > //-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ // [BT_debugger showIt:self:[NSString stringWithFormat:@"supportedInterfaceOrientationsForWindow %@", @""]]; // // //allow / dissallow rotations // BOOL canRotate = TRUE; // // //appDelegate // yourApp_appDelegate *appDelegate = (yourApp_appDelegate *)[[UIApplication sharedApplication] delegate]; // 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; // } // } // } // // //bitwise OR operator... // // NSUInteger mask = 0; // // // UNCOMMENT THIS TO SUPPORT iOS 6 SCREEN ROTATAIONS // // mask |= UIInterfaceOrientationMaskPortrait; // if(canRotate){ // mask |= UIInterfaceOrientationMaskLandscapeLeft; // mask |= UIInterfaceOrientationMaskLandscapeRight; // mask |= UIInterfaceOrientationMaskPortraitUpsideDown; // } // // // // return mask; //} Then add this - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown; if(self.window.rootViewController){ UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; orientations = [presentedViewController supportedInterfaceOrientations]; } return orientations; } In your plugin .m file in the view did load method add UIViewController *viewController = [[UIViewController alloc] init]; [self presentModalViewController:viewController animated:NO]; [self dismissModalViewControllerAnimated:NO]; [viewController release]; Then add this anywhere in the plugin .m file outside any curly braces - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; // this forces portrait } This will force landscape return UIInterfaceOrientationMaskLandscape; This will stop you control whether you can control rotation in control panel. Hope this helps
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/05/13 09:45 AM (12 years ago)
It is also best to set your development target to 5.1 as the method will become depreciated soon in ios6 although it does work at present
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/05/13 09:47 AM (12 years ago)
2 hours that took to work out but will be useful for a few of my plugins.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/05/13 10:48 AM (12 years ago)
Thanks Kittsy! You're awesome. I'll try it out later today when I get home.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/05/13 10:49 AM (12 years ago)
It seems to work on all the tests, it looks a little buggy on simulator, but perfect on device
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/05/13 11:06 AM (12 years ago)
Just looked at what you did, and I'm not sure it will work for what I'm trying to do. This is the last piece of the puzzle in the plugin I'm creating, so I need it to be contained within the plugin files. (can't exactly ask everyone who installs the plugin to override their appdelegate fle). I'm wondering, though, would it be possible to use a custom viewcontroller for a plugin? Can't we just copy most of whats in the current files into new ones, customize it, and then import the new files? Would address your issue with most of the github projects you found as well.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/05/13 11:34 AM (12 years ago)
Unfortunately it's a method that will only run from the appdelegate. The future of plugins will need to make chanes to appdelegate in the Instructions. Just look at the socialise/scringo tutorials if they want a feature they will have to make a change. I will take another look at the code
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/05/13 11:58 AM (12 years ago)
Hmm ok-well if other plugins require it, I guess mine can too. It's really only intended for more advanced uses of my plugin anyway. I think I'll add in your code with a JSON check first to see if user wants the option enabled, and include instructions on how to enable rotation prevention. Thanks
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/06/13 08:09 PM (12 years ago)
Hmm - so I just tried to implement your code suggestion, but it doesn't seem to do anything. I tried on simulator using 5.0, 5.1, and 6.0, and on actual devices using 5.1. It rotates every time. I didn't notice any bugginess, though. And, of course, it doesn't look like there's a way to pass anything in the debugger here for this process.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/06/13 08:34 PM (12 years ago)
sweet - I decided to go through stackoverflow one more time, thinking maybe I could find something that would work now that I've allowed for the fact that my instructions might have to include editing code. Somehow, though, I found a solution that works great and doesn't require any modification of the appdelegate or any other BT core files. Here's the gist: - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { float rotation; UIView *thisView = self.view; CGRect portraitFrame = noRotationRect; if (toInterfaceOrientation==UIInterfaceOrientationPortrait) { rotation = 0; portraitFrame = noRotationRect; } else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) { rotation = M_PI/2; portraitFrame = self.view.frame; } else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) { rotation = -M_PI/2; portraitFrame = self.view.frame; } [UIView animateWithDuration:duration animations:^{ thisView.transform = CGAffineTransformMakeRotation(rotation); thisView.frame = portraitFrame; }]; } The tabbar still rotates, but everything else stays the same. I had to adapt it a bit, as the proposed solution had the last line "thisView.frame = self.view.frame;", which worked okay for the first rotation of the device, but as soon as the device rotated back it was out of wack. The only variable here that isn't declared is noRotationRect, which is a CGFrame. I declared it in the .h file for my plugin, and set it equal to self.view.frame in my viewDidLoad.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/06/13 08:37 PM (12 years ago)
looks like it also works on ios 5 & 6
 

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.