Odd background image resizing on animating UIView
I have a UIView in the middle of a view that I am using as a game playing area (in a 2d cocoa view). This image has a background image of the same size as the view. Resizing the view I use animation to make it look smooth (and that works fine). However, when the animation starts, the background image immediately changes size, tiling or being clipped to a size that when the animation finishes, the background image is physically the same size.
I don't want this, I want the image to always fit the view, regardless of the view size.
UIImage *bgImage = [UIImage i开发者_JAVA技巧mageNamed:@"head.png"];
... // resize the image returning another image
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:resizedImage];
[UIView beginAnimations:@"resizeView" context:nil];
[UIView setAnimationDuration:.5];
int localViewSize = ... // work out view sizes
self.view.frame = CGRectMake(... ,localViewSize,localViewSize);
[UIView commitAnimations];
It looks very odd as it jumps to a different size, then animates to the original size.
I am guessing that maybe I would have to make a separate view underneath my main view but is that the only way?
I suspect that the "pattern image" is rendered to the layer contents (effectively a texture), and the layer contents are stretched to fit. The easy way around this is to set self.contentMode = UIViewContentModeCenter
or so; bear in mind that that works when your view grows but will probably display a blank border when your view is shrunk.
精彩评论