Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 7, 2009, 09:32 AM   #1
augeanst
macrumors newbie
 
Join Date: Mar 2008
Why are rotation codes such a pain in the rear?

I have been pulling my hair out for days, going down multiple blind paths; each no no end in sight. I am trying to do something that should be pretty simple. When the phone is in portrait mode I want UIView portrait to display. When in landscape I want UIView (yip you guessed it) landscape to load. Both of these UIViews are in the same nib file that is assoicated to my WERTYkeyboardForVIN class. Prior to adding any codes to switch views I am trying to just simply log to NSLog the current state (after that I will wrap my view codes in there).



I am sure I am screwing up something very simple (and stupid). Any thoughts or help would be greatly appreciated.



I am able to get shouldAutorotateToInterfaceOrientation to work:
Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
     NSLog(@"WERTYkeyboardForVIN shouldAutorotateToInterfaceOrientation");
     
     if (interfaceOrientation == UIInterfaceOrientationPortrait)
          {
          NSLog(@"    - shouldAutorotateToInterfaceOrientation - UIInterfaceOrientationPortrait, returning YES");
          return YES;
          }
     else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
          {
          NSLog(@"    - shouldAutorotateToInterfaceOrientation - UIInterfaceOrientationLandscapeRight, returning YES");
          return YES;
          }
     else 
          {
          NSLog(@"   - else - returning NO");
          return NO;
          }
}

As you would expect this outputs the following to the log:

WERTYkeyboardForVIN shouldAutorotateToInterfaceOrientation
- shouldAutorotateToInterfaceOrientation - UIInterfaceOrientationPortrait, returning YES



But when it comes to willAnimateRotationToInterfaceOrientation this method is never called and I am not sure why.

Code:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
     NSLog(@"WERTYkeyboardForVIN - willAnimateRotationToInterfaceOrientation");
     if (interfaceOrientation == UIInterfaceOrientationPortrait)
          {
          NSLog(@"    - willAnimateRotationToInterfaceOrientation - UIInterfaceOrientationPortrait");
          }
     else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
          {
          NSLog(@"   - willAnimateRotationToInterfaceOrientation - UIInterfaceOrientationLandscapeRight");
          }
     else 
          {
          NSLog(@"   - willAnimateRotationToInterfaceOrientation - else");
          }
}

I *think* my problem is with a different view controller being 'in control' of the screen, but I do not know how to find out. Is there a debugging code I can type in gdb to find out the currently active view controller?



FYI here is how I am initializing WERTYkeyboardForVIN from ACMainMenu.m (I have also tried the codes in this class thinking since it is a view controller it might be in control, but nope...)

Code:
     // Show WERTYkeyboardForVIN
     if (wERTYkeyboardForVIN == nil)
          {
          WERTYkeyboardForVIN *controller = [[WERTYkeyboardForVIN alloc] initWithNibName: @"WERTYkeyboardForVIN" bundle:[NSBundle mainBundle]];
          self.wERTYkeyboardForVIN = controller;
          [controller release];
          
          [appDelegate.window addSubview:[self.wERTYkeyboardForVIN view]];
          }
     else 
          {
          [appDelegate.window bringSubviewToFront:[self.wERTYkeyboardForVIN view]];
          }

Also I have tried placing my willAnimateRotationToInterfaceOrientation in the appDelegate to see if that was the problem, also tried it in my ACMainMenu (which is the primary view controller that is setup when the app launches).

thanks


Steven
augeanst is offline   0 Reply With Quote
Old Nov 8, 2009, 12:10 AM   #2
wlh99
macrumors 6502
 
Join Date: Feb 2008
I had problems getting autorotation to work too. It really isn't hard, but I found that deviating from the documented examples didn't work the way I expected them too.

Try re-writing the code so that only one UIView is used, and that view knows how to re-arrange itself. You may have to pragmatically build the view if it is complex. If it isn't complex, you can set some basic rules for how the subviews will move on the size and position tab of the inspector in IB.

If you really need multiple views, try creating a navigation controller with no navigation items. Push whatever orientation you want on the navigation controller's stack.
__________________
Warren Holybee
wlh99 is offline   0 Reply With Quote
Old Nov 8, 2009, 11:53 AM   #3
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Apple's design is for one view controller to receive the various callbacks (viewWillAppear, etc.) at a time. If you try to have more than one view controller active at one time it won't work.

UINavController and UITabBar know how to connect the frontmost view controller so it receives the callbacks. If you use those classes and have only a single view controller active at a time then things should 'just work.'

Why it works this way and what the nav controller and tab bar do to make it work correctly just isn't known.
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPad: Rotation issues Ipadlover29 iPad 1 Dec 2, 2013 06:35 AM
4S, ios 6.1.3 and pain spaceryder iPhone 1 Oct 31, 2013 06:58 PM
iPhone: Is it me or did they remove rotation? Nuworld iOS 7 6 Sep 18, 2013 09:20 PM
rotation problem LARRYSE iPhone/iPad Programming 1 Jan 30, 2013 12:59 PM
Sincerely did not mean to cause such pain. vpro Community Discussion 2 Sep 23, 2012 04:04 PM

Forum Jump

All times are GMT -5. The time now is 04:30 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC