views:

1413

answers:

1

I am having a problem with a UIView that when using a solid colour for the background, animates perfectly fine.

However when I set a background image for it's colour instead, the UIView animation doesn't work properly. It looks like a ghost outline of the page curl, but the UIView itself is 100% transparent (If that makes sense).

The image's background colour is set beforehand like so (which screws up the animation):

UIImage *loadedImage = [UIImage imageNamed:@"MyTexture.png"];
UIColor *tempColour = [[UIColor alloc] initWithPatternImage:loadedImage];
[myUIView setBackgroundColor:tempColour];
[tempColour release];

Setting the background colour to solid however, lets the animation work fine:

[myUIView setBackgroundColor:[UIColor blackColor]];

The animation I am using:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];   
[UIView setAnimationTransition:UIViewAnimationCurveLinear forView:myUIView cache:YES];
[myUIView setHidden:YES];
[UIView commitAnimations];
+1  A: 

In my experience the most reliable way to get an image to work as a background within iphone apps is to use a separate UIImageView on which you'd set your background image. You can then set the UIImageView as the bottom level view and put your other views on top of it.

In the views you put on top of it you set backgroundColor to [UIColor clearColor] and that gives you in effect what you are trying to do here.

I've used this in a couple of apps successfully and it is much more reliable than setting an image directly on the UIView background (which I tried before as well).

Hope that helps.

paulthenerd