Rotating scrollview with CGAffineTransformMakeRotation

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

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

    BarryK88 macrumors member

    Mar 1, 2011
    I'm making an scrollview within a view of the iPad. It should switch positions after rotating. It works however when I rotate my device twice the scroller gets out of my screen.

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    		interfaceOrientation == UIInterfaceOrientationLandscapeRight){
    		interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
    			backgroundImage.image = [UIImage imageNamed:@"landscape.png"];
    			scroller.transform = CGAffineTransformMakeRotation(M_PI/2);
    			scroller.frame = CGRectMake(0, 108, 130, 750);
    			scroller.contentSize = CGSizeMake(1040, 130);
    			scroller.scrollEnabled = YES;
    if(interfaceOrientation == UIInterfaceOrientationPortrait ||
    	   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
    		interfaceOrientation == UIInterfaceOrientationPortrait;
    backgroundImage.image = [UIImage imageNamed:@"portrait.png"];
    		scroller.transform = CGAffineTransformMakeRotation(M_PI*2);
    		scroller.frame = CGRectMake(0, 870, 768, 128);
    		scroller.contentSize = CGSizeMake(940, 128);			
    Think I'm making a mistake with my angle calculations. However i saw the following on the UIView CLass reverence about the transform property " if this property is not the identity transform, the value of the frame property is undefined and therefor should be ignored"

    However I still can't figure it out. Some help would be realy appreciated.
  2. ClutchThese macrumors 65816


    Jun 25, 2010
    Alexandria, VA
    is there a reason you don't like to use IB? i think it is so much easier to deal with rotation and such via the pictoral interface builder.
  3. BarryK88 thread starter macrumors member

    Mar 1, 2011
    It's not possible to do this in the interface builder because the sizes of the scrollers are a bit different same goes for the location in landscape view.
    Landscape -> (0, 108,) with a Width and Height (130, 800)
    Portrait -> (0, 870) with a Width and Height (768, 130)

    When I rotate this with IB the scroller stays horizontal in stead of a vertical one in Landscape view. it's also impossible to get the right coordinates.

Share This Page