您的位置:首页 > 其它

CAGradientLayer实现向右滑动解锁的动画效果

2017-07-22 15:37 309 查看
    //bgView
   
UIView *bottomView = [[UIView
alloc] initWithFrame:CGRectMake(0.0f,
self.view.height-120.0f,
self.view.width,
60.0f)];
    bottomView.backgroundColor = [UIColor
grayColor];
    [self.view
addSubview:bottomView];

    

    CAGradientLayer *gradinetLayer = [CAGradientLayer
layer];
    [bottomView.layer
addSublayer:gradinetLayer];
    gradinetLayer.frame =
CGRectMake(0,
10, bottomView.width,
30);
    gradinetLayer.startPoint =
CGPointMake(0,
0.5);//要确定startPoint
    gradinetLayer.endPoint =
CGPointMake(1,
0.5);//确定endPoint,这二者共同决定动画滚动的方向
    gradinetLayer.colors =
@[
                             (__bridge
id)[UIColor
blackColor].CGColor,
                             (__bridge
id)[UIColor
whiteColor].CGColor,
                             (__bridge
id)[UIColor
blackColor].CGColor
                            
];
    gradinetLayer.locations =
@[@0.25,@0.5,@0.75];

    // 添加部分

    CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"locations"];
    basicAnimation.fromValue =
@[@0, @0,
@0.25];
    basicAnimation.toValue =
@[@0.75, @1,
@1];
    basicAnimation.duration =
2.0;
    basicAnimation.repeatCount =
HUGE;
    [gradinetLayer
addAnimation:basicAnimation
forKey:nil];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐