Auto rotation help

Discussion in 'iOS Programming' started by henktade, Jan 30, 2009.

  1. henktade macrumors newbie

    Joined:
    Jan 30, 2009
    #1
    #import "AutosizeViewController.h"

    @implementation AutosizeViewController
    @synthesize button1;
    @synthesize button2;
    @synthesize button3;
    @synthesize button4;
    @synthesize button5;
    @synthesize button6;

    -(void)willAnimateSecondHalfOfRotationFromInterfaceOrinetation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {

    UIInterfaceOrientation toOrientation = self.interfaceOrientation;
    [UIView beginAnimations:mad:"move buttons" context:nil];

    if(toOrientation == UIInterfaceOrientationPortrait || toOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
    button1.frame = CGRectMake(20, 20, 125, 125);
    button2.frame = CGRectMake(175, 20, 125, 125);
    button3.frame = CGRectMake(20, 168, 125, 125);
    button4.frame = CGRectMake(175, 168, 125, 125);
    button5.frame = CGRectMake(20, 315, 125, 125);
    button6.frame = CGRectMake(175, 315, 25, 25);
    }
    else
    {
    button1.frame = CGRectMake(20, 20, 125, 125);
    button2.frame = CGRectMake(20, 155, 125, 125);
    button3.frame = CGRectMake(177, 20, 125, 125);
    button4.frame = CGRectMake(177, 155, 125, 125);
    button5.frame = CGRectMake(328, 20, 125, 125);
    button6.frame = CGRectMake(328, 155, 100, 100);
    }
    [UIView commitAnimations];
    }

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
    //(interfaceOrientation == UIInterfaceOrientationPortrait ||
    // interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
    // interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    // interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
    }
    - (void)dealloc {
    [button1 release];
    [button2 release];
    [button3 release];
    [button4 release];
    [button5 release];
    [button6 release];
    [super dealloc];
    }

    @end

    hello .. can any body advice me what is wrong with this code. it runs but the button do not change there position in the way I want them to change as discribed in the willAnimateSecondHalfOfRotationFromInterfaceOrinetation method.

    tanks in advance :)
     
  2. henktade thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #2
    guys say some thing

    guys!!!! say some thing.. is kind of urgent...
     
  3. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #3
    Here's Apple's primer on view geometry.

    Basically the coordinate system remains with its origin in the top left-hand corner on rotation, so you need to work out where you want your buttons in the new coordinate system.

    You also don't seem to have a case in your willAnimateSecondHalfOfRotationFromInterfaceOrinetation method to handle landscape mode.

    More fundamentally, "Orientation" is spelt wrong in "willAnimateSecondHalfOfRotationFromInterfaceOrinetation" – are you sure it's actually being called?
     
  4. henktade thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #4
    tanks Jnic it is ok now.
     

Share This Page