0

I would like the background image of a view to change every time there's rotation. The image changes, yet when the rotation is horizontal, it cuts it off as if it were a portrait image. Here's what I mean: enter image description here

This orientation is horizontal, yet the image is cropped for portrait dimensions. The actual image is fit to be horizontal.

Here's my code:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// called after rotation occurs

if (fromInterfaceOrientation == UIInterfaceOrientationPortrait) {
    // now horizontal
    imageToLoad = [UIImage imageNamed:@"H0.png"];
} else {
    // now portrait
    imageToLoad = [UIImage imageNamed:@"P0.png"];
}
UIGraphicsBeginImageContext(self.view.frame.size);
[imageToLoad drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.view.backgroundColor = [UIColor colorWithPatternImage:image];
}

How could I solve this? Thank you.

4

1 回答 1

0

为什么要使用背景颜色?添加一个UIImageView具有适当的自动调整大小掩码和内容模式。

于 2013-06-19T19:59:09.910 回答