Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BarryK88

macrumors member
Original poster
Mar 1, 2011
31
0
Dear fellow Macrumors members,

I'm creating an iPad app with a UIScrollview. Within this scrollview there are several images and textfields.

When I'm rotating the iPad (to landscape) i'd like to put the images in vertical order and in Portrait in horizontal order.

I already succeeded with making the scrollview within these two views. Is there anyone who can give me some advice about this issue?

Here is a part of my code that I programmed within the shouldautorotate method.

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	
	
	if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
	   interfaceOrientation == UIInterfaceOrientationLandscapeRight){
		interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
	   
		backgroundImage.image = [UIImage imageNamed:@"Achtergrond_Liggend_Opstelling.png"];
		scroller.frame = CGRectMake(0, 104, 130, 660);
		scroller.contentSize = CGSizeMake(130, 1200);
		
	}
	if(interfaceOrientation == UIInterfaceOrientationPortrait ||
	   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
		interfaceOrientation == UIInterfaceOrientationPortrait;
		
		backgroundImage.image = [UIImage imageNamed:@"Achtergrond_Staand_Opstelling.png"];
		scroller.frame = CGRectMake(0, 890, 768, 112);
		scroller.contentSize = CGSizeMake(1200, 112);
		scroller.showsHorizontalScrollIndicator = FALSE;		
	}
	[super viewDidLoad];
}
Hope someone got some good tips.
 
Last edited by a moderator:
One not so efficient way to achieve this could be to create two scrollviews and duplicate all their content (images and text) in both orientations. In IB you can create one scrollview in portrait and one in landscape. Then in your if statements something like

Code:
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
	   interfaceOrientation == UIInterfaceOrientationLandscapeRight){
		interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
	   
		scrollview1.hidden=NO; 
                scrollview2.hidden=YES;
		
	}
	if(interfaceOrientation == UIInterfaceOrientationPortrait ||
	   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
		interfaceOrientation == UIInterfaceOrientationPortrait;
		
		scrollview1.hidden=YES; 
                scrollview2.hidden=NO;	
	}

This is a memory wasting solution but it should work.

Nick
 
The PhotoScroller sample code does something like this. It lets you swipe through several images by using a scroller. The photos are always horizontal but the app massages frames and other stuff when the device rotates.
 
Figured it out. I just made a function for every image when rotated.

like

Code:
image.transform = CGAffineTransformMakeRotation(-M_PI/2);

thanks anyway:)
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.