[英]UIView background image not rotating
I've got an app that has two different background images. 我有一个具有两个不同背景图像的应用程序。 The one selected is determined by the orientation.
选择的一个由方向确定。 When I start out, I check self.interfaceOrientation, and then go and pick the proper image.
当我开始时,我检查self.interfaceOrientation,然后去选择合适的图像。 However, whenever the view opens, part of the image repeats instead of stretching.
但是,只要打开视图,图像的一部分就会重复而不是拉伸。 I saw a previous answer applying autoresizing masks to an imageview, but there is no imageview that I'm currently using.
我看到了以前的答案,将自动调整大小的蒙版应用到imageview,但是当前没有使用imageview。
Inside the loadView method: 在loadView方法内部:
if(self.interfaceOrientation==UIInterfaceOrientationPortrait ||self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"portrait"]]];
}else{
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"landscape"]]];
}
As rishi had pointed out, the issue was caused by the colorWithPatternImage method. 正如rishi所指出的,该问题是由colorWithPatternImage方法引起的。 What I did to resolve this was to set the background of the view to be a specified image.
我要做的就是将视图的背景设置为指定的图像。
UIImageView* bgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed: @"foo.png"]];
[self.view addSubview: bgView];
I also added in flexible width and height so that it would rotate properly. 我还添加了灵活的宽度和高度,以便可以正确旋转。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.