Search code examples
objective-cios5orientation-changes

iOS 5 objective C orientation


I am learning to dvelop applications for iPhone on iOS5. I have no prior experience with any other version. I wanted to support multiple orientations and i have been searching a lot lately. But i have not found a solution.

1) I could use a navigation controller, which would push and pop view controllers in and out of the stack according to the orientation changes. But that would mean that i'll have to make 2 copies of everything, one for landscape and one for potrait.

2) I make a new landscape view controller. In willRotateToInterfaceOrientation method of potrait view controller I initialize an instance of the landscpe view controller and set it as presentViewController. In landscape VC, i initialize an instance of potrait and do the same. But I think this would just take up more and more memory because this instances are nmot being 'popped' as in the case of navigation controller. (i have not yet read the memory management guide)

3) There were some things about the resizing of the view. I did really understand this method.

Please suggest what is the method that is generally used and why.


Solution

  • Not need to create separate ViewController for Landscape and portrait.

    If suppose You have a button named btnSample.
    
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
      UIInterfaceOrientation des=self.interfaceOrientation;
      if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown))
        {
    

    //Portrait

    btnSample.frame=CGRectMake(10,10,100,70);
    
        }
      else
      {
    

    //Landscape

    btnSample.frame=CGRectMake(200,100,100,70);
    
      }
    

    }