Search code examples
iphoneuitableviewuiscrollviewuipagecontrol

How add scroll view with page control when device rotate to left or right?


I am designing an application in which i have a table view controller. Now I want that when I rotate device then instead of table view a scroll with page control will appear. So that I can scroll image with page control.

And when I again rotate to portrait mode then it will so again table view.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Return YES for supported orientations
  if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
    self.navigationController.navigationBarHidden=TRUE;
    self.tabBarController.tabBar.hidden=TRUE;


  }
  else{
    self.navigationController.navigationBarHidden=FALSE;
    self.tabBarController.tabBar.hidden=FALSE;
    self.tableView.hidden=FALSE;

  }

  return YES;
}

How do I achieve this?


Solution

  • You can implement didRotateFromInterfaceOrientation to detect when the screen rotates, then add your code to add/show/remove/hide/whatever your views based on the current orientation.

    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
        switch (self.interfaceOrientation) {
            case UIInterfaceOrientationPortrait:
                //Do stuff
                break;
    
            default:
                break;
        }
    }
    

    self.interfaceOrientation gives the current orientation, (portrait, upsidedown, landscapeleft, landscaperight), and you also have access to the previous orientation if you need it.