0

I am doing a project which supports both landscape mode and portrait mode,but now i am struck there is no orentation in my project.I set the

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    //return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    return YES;
}

but no use,when i press the command +Right-arrow for rotation to right it rotates to left but view and controllers didnt change to that orentation.Then after some googling i get this code

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
    // do stuff
}

But the problem is i didn't know how to write code in //do stuff.Please help me to do this. thanks in advance. EDIT: i put this code ,it is working but whenthe simulator is again turns to portrait it wont be in the default mode.my code is

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    {
        if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
        {
            NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: left or right");
            //
            table.transform = CGAffineTransformIdentity;
            table.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
            table.bounds = CGRectMake(0.0, 0.0, 320, 402);//[self.view setFrame:CGRectMake(0.0, 0.0, 768, 90)];
        }
        else
        {
            table.transform = CGAffineTransformIdentity;
            table.transform = CGAffineTransformMakeRotation(degreesToRadian(360));
            table.bounds = CGRectMake(0.0, 51, 320, 402);
        }
               return YES;
   }*/
ICoder
  • 1,347
  • 2
  • 13
  • 23
  • Possible duplicate: http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation – Dair Nov 07 '11 at 05:39

2 Answers2

1
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
    {
        //Handle portrait
    }
    else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
     {
         //Handle landscape
     }
}

This is better code.

Satyam
  • 15,493
  • 31
  • 131
  • 244
  • i put this inside the landscape orientation but nothing done self.view.transform = CGAffineTransformIdentity; self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); self.view.bounds = CGRectMake(0.0, 0.0, 480, 320); – ICoder Nov 07 '11 at 07:53
  • You don't have to make rotation at all..... all your controls change automatically. you just have to set their frame. in the method "shouldAutorotateToInterfaceOrientation", you just return yes. and set the frame in "willRotateToInterfaceOrientation" – Satyam Nov 08 '11 at 16:54
0

You can do like this.

if (UIInterfaceOrientationPortrait == interfaceOrientation || UIInterfaceOrientationLandscapeLeft == interfaceOrientation || UIInterfaceOrientationLandscapeRight == interfaceOrientation ||
    UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation) {
    return  YES;
}
mandeep-dhiman
  • 2,505
  • 2
  • 21
  • 31