Ios 在空ViewController xcode 5中设置约束

Ios 在空ViewController xcode 5中设置约束,ios,objective-c,xcode5,autolayout,nslayoutconstraint,Ios,Objective C,Xcode5,Autolayout,Nslayoutconstraint,我有一个空的ViewController。从程序上来说,我把地面图像放回原处 - (void)setBackGroundImg:(NSString*) name { UIGraphicsBeginImageContext(self.view.frame.size); [[UIImage imageNamed:name] drawInRect:self.view.bounds]; UIImage *image = UIGraphicsGetImageFromCurrent

我有一个空的ViewController。从程序上来说,我把地面图像放回原处

- (void)setBackGroundImg:(NSString*) name {

    UIGraphicsBeginImageContext(self.view.frame.size);
    [[UIImage imageNamed:name] drawInRect:self.view.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.backgroundColor = [UIColor colorWithPatternImage:image];

}
问题: 我正在模拟器中运行应用程序。如果没有旋转,它看起来像这样

但当我旋转模拟器应用程序时,它是这样的


你知道我该如何解决这个问题吗?我正在使用Xcode 5,并启用了自动布局。我看不出如何在空ViewController中设置约束。如果您希望在设备旋转时图像自动旋转,请在UIImageView中显示图像,而不是手动绘制图像。查看UIImageView文档。

只需使用9路径,例如:

self.view.backgroundColor = [UIColor colorWithPatternImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];

模式映像将复制自身。你想达到什么目标?也许可以用另一种方式来做。@vokilam我想先摆脱这种重复,当我旋转模拟器图像时,这可能吗?你说的旋转本身是什么意思?@vokilam你可以在图片中看到,当模拟器旋转时,图像不旋转