ios – 在xCode中创建类似于Solar Weather Application的动画渐变背景

即使我以前提过这个问题,我想再次提出来,澄清我想要帮助的内容.我想知道如何在xCode中创建一个背景和iOS应用程序,类似于随着时间的推移而变化的太阳天气应用程序(屏幕截图)的背景.正如你可以看到,渐变很顺利,显然包含两个以上的要点.
任何帮助的例子或代码片段将不胜感激.再次感谢,本.

解决方法

我需要的是:

>将CAGradientLayer添加到视图控制器(或自定义视图)中,例如:

@property (nonatomic,retain) CAGradientLayer *gradient;

>在视图控制器中,在viewDidLoad中,创建并添加渐变图层到您的视图:

self.gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:
               (id)topColor.CGColor,(id)bottomColor.CGColor,nil];
gradient.locations = [NSArray arrayWithObjects:
                  [NSNumber numberWithFloat:0.0f],[NSNumber numberWithFloat:0.7],nil];
[self.view.layer addSublayer:self.gradient];

3A.添加一个NSTimer到您的控制器将通过执行以适当的时间间隔更新self.gradient:

topColor = ...; bottomColor = ...;
  NSArray* newColors = [NSArray arrayWithObjects:
                 (id)topColor.CGColor,nil];
 [(CAGradientLayer *)self.layer setColors:newColors];

这将允许您在每个步骤中准确地确定要用于渐变的颜色.否则,您可以尝试使用动画,如下所示:

3B.添加这样的动画,

- (void)animateLayer... {

  [UIView animateWithDuration:duration 
                        delay:0
                      options:UIViewAnimationOptionCurveEaseInOut
                   animations:^{
    [CATransaction begin];
    [CATransaction setAnimationDuration:duration];

      topColor = ...; bottomColor = ...;
      NSArray* newColors = [NSArray arrayWithObjects:
                 (id)topColor.CGColor,nil];
     [(CAGradientLayer *)self.layer setColors:newColors];

     [CATransaction commit];
  }
          completion:^(BOOL b) {
              [self animateLayer..];
          }];
}

您也可以组合3a和3b.

以上是来客网为你收集整理的ios – 在xCode中创建类似于Solar Weather Application的动画渐变背景全部内容,希望文章能够帮你解决ios – 在xCode中创建类似于Solar Weather Application的动画渐变背景所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。