我的应用程序的背景渐变有问题。我进去viewDidLoad
了MainViewController
。
CAGradientLayer *bgLayer = [BackgroundGradient blackGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
并且每个都UIViewController
从MainViewController
. 它工作正常,但旋转设备后它只显示一半背景。其他是白色的。你能帮我吗?问题出在哪里,旋转后只显示一半?
在 BackgroundGradient.m 中
@implementation BackgroundGradient
+ (CAGradientLayer*) blackGradient {
UIColor *colorOne = [UIColor colorWithRed:0.12 green:0.13 blue:0.13 alpha:1.0];
UIColor *colorTwo = [UIColor colorWithRed:0.11 green:0.12 blue:0.13 alpha:1.0];
NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];
NSNumber *stopOne = [NSNumber numberWithFloat:0.0];
NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];
NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil];
CAGradientLayer *headerLayer = [CAGradientLayer layer];
headerLayer.colors = colors;
headerLayer.locations = locations;
return headerLayer;
}