How can i handle the orientation change in iPhone / iPad application? Please suggest.
Thank in Advance!
Given is the method to manage or change the orientation in iPad application
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } // orientation view swapping logic - (void)didRotate:(NSNotification *)notification { UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation]; if (newOrientation != UIDeviceOrientationUnknown || newOrientation != UIDeviceOrientationFaceUp || newOrientation != UIDeviceOrientationFaceDown) { orientation = newOrientation; } // Write your orientation logic here if ((orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)) { // Clear the current view and insert the orientation specific view. [self clearCurrentView]; [self.view insertSubview:yourLandscapeView atIndex:0]; } else if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) { // Clear the current view and insert the orientation specific view. [self clearCurrentView]; [self.view insertSubview:yourPortraitView atIndex:0]; } }
Given is the method to manage or change the orientation in iPad application
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } // orientation view swapping logic - (void)didRotate:(NSNotification *)notification { UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation]; if (newOrientation != UIDeviceOrientationUnknown || newOrientation != UIDeviceOrientationFaceUp || newOrientation != UIDeviceOrientationFaceDown) { orientation = newOrientation; } // Write your orientation logic here if ((orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)) { // Clear the current view and insert the orientation specific view. [self clearCurrentView]; [self.view insertSubview:yourLandscapeView atIndex:0]; } else if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) { // Clear the current view and insert the orientation specific view. [self clearCurrentView]; [self.view insertSubview:yourPortraitView atIndex:0]; } }
Ads