【问题标题】:view background color in ios在 ios 中查看背景颜色
【发布时间】:2016-03-18 04:01:55
【问题描述】:
我已经为视图添加了背景颜色。当我将方向纵向更改为横向颜色时,我会折叠。我附上了屏幕截图。
肖像:
风景:
CAGradientLayer *color = [back_color blackWhiteGradient];
color.frame = self.back_view.bounds;
[self.back_view.layer insertSublayer:color atIndex:0];
谢谢……
【问题讨论】:
标签:
ios
colors
background
【解决方案1】:
我刚刚添加了下面的代码,它工作得很好。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// resize your layers based on the view’s new bounds
[[[self.back_view.layer sublayers] objectAtIndex:0] setFrame:self.back_view.bounds];
}
【解决方案2】:
CAGradientLayer *color = [back_color blackWhiteGradient];
color.frame = self.back_view.bounds;
[self.back_view.layer insertSublayer:color atIndex:0];
当方向改变时调用此代码并在方向改变时使其实例变量也首先删除渐变然后重新创建渐变。
这不起作用,因为渐变会根据其屏幕尺寸应用,因此当方向改变时它不会自动重新绘制其表面。
【解决方案3】:
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
// code for landscape orientation
}
OR
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
// code for Portrait orientation
}
根据方向改变渐变,然后你会得到准确的颜色,你可以像这样设置肖像的渐变。
希望这对你有帮助....