2014-12-05 118 views
0

我的應用程序背景漸變有問題。我在viewDidLoad中設置了MainViewController旋轉背景漸變xcode

CAGradientLayer *bgLayer = [BackgroundGradient blackGradient]; 
bgLayer.frame = self.view.bounds; 
[self.view.layer insertSublayer:bgLayer atIndex:0]; 

UIViewControllerMainViewController延伸。它工作正常,但旋轉設備後,它顯示我只有一半的背景。其他是白色的。你能幫我嗎?哪裏可以成爲問題,並顯示旋轉後只有一半? example

在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; 
} 

回答

1

保存層到控制器屬性,比覆蓋layoutSubviews方法和更新層幀。

- (void)layoutSubviews { 
    [super layoutSubviews]; 
    self.backgroundLayer.frame = self.view.bounds; 
}