Reputation: 313
I have a problem with my background gradient on my app. I set in viewDidLoad
in MainViewController
.
CAGradientLayer *bgLayer = [BackgroundGradient blackGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
and every UIViewController
extends from MainViewController
. It works fine but after rotate device it show me only half background. Other is white. Can you help? Where can be the problem and show me it only half after rotate?
In 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;
}
Upvotes: 0
Views: 497
Reputation: 11801
Save your layer into controller property, than override layoutSubviews
method and update layer frame.
- (void)layoutSubviews {
[super layoutSubviews];
self.backgroundLayer.frame = self.view.bounds;
}
Upvotes: 1