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

Zvi

macrumors newbie
Original poster
Sep 29, 2008
7
0
Hi All,

I have a background image which is created in viewDidLoad
Code:
	bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background_2.png"]];
	[self.view addSubview:bgView];
	[self.view sendSubviewToBack:bgView];

All fine. Then, rotation:

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return TRUE;
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
	//[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
	return;
	CGRect bgRect = bgView.bounds;

	if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || 
		 toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
	{
		//[bgView setBounds:CGRectMake(bgRect.origin.y, bgRect.origin.x, bgRect.size.height, bgRect.size.width)];
		bgView.transform = CGAffineTransformMakeRotation(3.14159265/2);

	}
	
	if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
	{
		//[bgView setBounds:CGRectMake(bgRect.origin.y, bgRect.origin.x, bgRect.size.height, bgRect.size.width)];
		bgView.transform = CGAffineTransformMakeRotation(3.14159265/2);
	}
}

However, this transform has no effect. View rotates, but the image stays in vertical position, so the right half of the view has no bg.

I've also tried to set new rect on the bgView as you can see form the commented code. Doesn't help, makes things worse. In landscape things are the same as w/o rect change, but when the view goes back to portrait bg image is moved down by 40-50 pix. No idea why.

I've also tried to bring bgView to front, rotate and send back again, no effect either. I'm sortta out of ideas here :(

So, what am I missing?
 

Zvi

macrumors newbie
Original poster
Sep 29, 2008
7
0
I think you need to set the autoresize property for the bgview.

I've added:
Code:
[bgView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
I've fixed it.
I needed same flag on parent view too. After setting autoresize on main view all works fine.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.