gpt4 book ai didi

iphone - iOS - 旋转 View 显示背景

转载 作者:行者123 更新时间:2023-11-29 11:24:33 24 4
gpt4 key购买 nike

我已经创建了一个我希望能够旋转的 View 。这两个 View 是:containerView,它有一个红色的 .backgroundColor 和一个作为 subview 的 BackgroundImage。这是我的旋转代码:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
backgroundImage.image = [UIImage imageNamed:@"landscape.jpg"];
backgroundImage.frame = CGRectMake(0, 0, 1024, 704);
containerView.frame = CGRectMake(0, 0, 1024, 704);
self.title = @"landscape";
} else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
backgroundImage.image = [UIImage imageNamed:@"portrait.jpg"];
backgroundImage.frame = CGRectMake(0, 0, 768, 960);
containerView.frame = CGRectMake(0, 0, 768, 960);
self.title = @"portrait";
}
}

问题是图像旋转了,但是背景颜色在 View 旋转时显示了。这个问题有没有很好的解决方案(我知道我可以创建图像以混合成一种颜色并将背景设置为相同的颜色,但这不是我想要的)。

可以在这里看到问题的视频:http://tinypic.com/r/2quj24g/6

PS 图片来自OmniGroup GitHub repo并且仅用于演示。

最佳答案

此问题的解决方案是将 UIView 或 UIWindow 的 backgroundColor 设置为 [UIColor blackColor]。当你旋转 Safari 时,同样的事情会发生,只是背景颜色是黑色的,就像它通常应该的那样。 iPad 上的所有应用程序都以这种方式旋转,用户不会注意到任何差异。

PS- 不使用 willRotateToInterfaceOrientation:duration: 方法,而是使用 willAnimateRotationToInterfaceOrientation:duration:

关于iphone - iOS - 旋转 View 显示背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3054365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com