Resize iPhone images when rotated

I have an application with many views. I want only a few views to rotate horizontally when the device rotates. I found out that I cannot use (BOOL)shouldAutorotateToInterfaceOrientation , because this will rotate every view in my application. I found a solution to this problem here in Stack Overflow, but now I have another problem.

The view rotates when I rotate the device, but it still shows the view as if it was still in portrait mode (straight up and down). The top and bottom of the image are cut off. Is there a way to rotate the view, as well as adjust its size to fit the new orientation? I also found this one , but couldn't get it to work.

Here is my code for this view:

 @implementation businessBank @synthesize webView, activityIndicator; - (void)viewDidLoad { [super viewDidLoad]; NSString *urlAddress = @"website_url"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)didRotate:(NSNotification *)notification { UIDeviceOrientation orientation = [[notification object] orientation]; if (orientation == UIDeviceOrientationLandscapeLeft) { [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)]; } else if (orientation == UIDeviceOrientationLandscapeRight) { [self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)]; } else if (orientation == UIDeviceOrientationPortraitUpsideDown) { [self.view setTransform:CGAffineTransformMakeRotation(M_PI)]; } else if (orientation == UIDeviceOrientationPortrait) { [self.view setTransform:CGAffineTransformMakeRotation(0.0)]; } } 
+6
iphone resize rotation orientation
source share
1 answer

Unless you have a very simple application that stretches to fit the orientation, automatic resizing will not work for you anyway - you really need to create two separate views for the two orientations.

For help with automatic view views, you can check out this tutorial:

http://theappleblog.com/2009/04/08/iphone-dev-sessions-how-to-make-an-orientation-aware-clock/

To use a more robust method of switching views, this tutorial should help you:

http://icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/

+3
source share

All Articles