How to reset content within a UIScrollview on orientation

Discussion in 'iOS Programming' started by BarryK88, Mar 1, 2011.

  1. BarryK88, Mar 1, 2011
    Last edited by a moderator: Mar 1, 2011

    BarryK88 macrumors member

    Joined:
    Mar 1, 2011
    #1
    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.
     
  2. nickculbertson macrumors regular

    nickculbertson

    Joined:
    Nov 19, 2010
    Location:
    Nashville, TN
    #2
    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
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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.
     
  4. BarryK88, Mar 4, 2011
    Last edited by a moderator: Mar 10, 2011

    BarryK88 thread starter macrumors member

    Joined:
    Mar 1, 2011
    #4
    Figured it out. I just made a function for every image when rotated.

    like

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

Share This Page