ios(CoreAnimation核心动画一)CABasicAnimation动画 - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 技术分享 >

ios(CoreAnimation核心动画一)CABasicAnimation动画

发表时间:2020-10-19

发布人:葵宇科技

浏览次数:64


一、position和anchorPoint
position:用来设置CALayer在父层中的地位,以父层的左上角为原点(0, 0)
anchorPoint(锚点):
称为“定位点”、“锚点”
决定着CALayer身上的哪个点会在position属性所指的地位
以本身的左上角为原点(0, 0)
它的x、y取值范围都是0~1,默认值为(0.5, 0.5)
推荐一个连接:http://www.cnblogs.com/wendingding/p/3800736.html讲的异常具体,并且有图视,默认的锚点为中间点:(0.5,0.5),如不雅从新设置了锚点,运行动画的时刻会发明全部控件移动了,所以在设置锚点的时刻须要从新设置position,

 CGPoint oldAnchorPoint = _homeBtn.layer.anchorPoint;
    _homeBtn.layer.anchorPoint =CGPointMake(0.5,0);
     [_homeBtn.layersetPosition:CGPointMake(_homeBtn.layer.position.x + _homeBtn.layer.bounds.size.width * (_homeBtn.layer.anchorPoint.x - oldAnchorPoint.x),_homeBtn.layer.position.y +_homeBtn.layer.bounds.size.height * (_homeBtn.layer.anchorPoint.y - oldAnchorPoint.y))];




二:CABasicAnimation的应用
当你创建一个 CABasicAnimation 时,你须要经由过程-setFromValue 和-setToValue 来指定一个开端值和停止值。 当你增长基本动画到层中的时刻,它开端运行。
Autoreverses
当你设定则个属性为 YES 时,在它达到目标地之后,动画的返回到开端的值,代替了直接跳转到 开端的值。
Duration
Duration 这个参数你已经相当熟悉了。它设定开端值到停止值花费的时光。时代会被速度的属性所影响。 RemovedOnCompletion
这个属性默认为 YES,那意味着,在指定的时光段完成后,动画就主动的大年夜层上移除了。这个一般不消。
假如你想要再次用这个动画时,你须要设定则个属性为 NO。如许的话,下次你在经由过程-set 办法设定动画的属 性时,它将再次应用你的动画,而非默认的动画。
Speed
默认的值为 1.0.这意味着动画播放按照默认的速度。如不雅你改变┞封个值为 2.0,动画会用 2 倍的速度播放。 如许的影响就是使持续时光减半。如不雅你指定的持续时光为 6 秒,速度为 2.0,动画就会播放 3 秒钟---一半的 持续时光。
BeginTime
这个属性在组动画中很有效。它根据父动画组的持续时光,指定了开端播放动画的时光。默认的是 0.0.组 动画鄙人个段落中评论辩论“Animation Grouping”。
TimeOffset
如不雅一个时光偏移量是被设定,动画不会真正的可见,直到根据父动画组中的履行时光获得的时光都流逝 了。
RepeatCount
    mask
默认的是 0,意味着动画只会播放一次。如不雅指定一个无穷大年夜的反复次数,应用 1e100f。这个不该该和 repeatDration 属性一块应用。
RepeatDuration
这个属性指定了动画应当被反复多久。动画会一向反复,直到设定的时光流逝完。它不该该和 repeatCount 一路应用。 
示例代码:

    backgroundColor    背景色彩

    
    CGPoint fromPoint = self.testImage.center;
    
    //路径曲线controlPoint为基准点
    UIBezierPath * movePath = [UIBezierPath bezierPath];
    [movePath moveToPoint:fromPoint];
    CGPoint toPoint = CGPointMake(300, 460);
    [movePath addQuadCurveToPoint:toPoint controlPoint:CGPointMake(300, 0)];
    
    //关键帧  设置动画路径
    CAKeyframeAnimation * moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//    moveAnimation.path = movePath.CGPath;
    moveAnimation.values = @[[NSValue valueWithCGPoint:CGPointMake(100, 100)],[NSValue valueWithCGPoint:CGPointMake(100, 300)],[NSValue valueWithCGPoint:CGPointMake(300, 300)],[NSValue valueWithCGPoint:CGPointMake(300, 100)]];
    moveAnimation.removedOnCompletion = YES;
    
    //缩放变更
    CABasicAnimation * scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
    scaleAnimation.fromValue = http://www.sjsjw.com/100/000077MYM008781/[NSValue valueWithCATransform3D:CATransform3DIdentity];
    scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
    scaleAnimation.removedOnCompletion = YES;
    
//    //透明度变更
//    CABasicAnimation * opacityAnimation = [CABasicAnimation animationWithKeyPath:@"alpha"];
//    opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0];
//    opacityAnimation.toValue = [NSNumber numberWithFloat:0.1];
//    opacityAnimation.removedOnCompletion = YES;
    
    //扭转
    CABasicAnimation * tranformAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    tranformAnimation.fromValue = [NSNumber numberWithFloat:0.f];
    tranformAnimation.toValue = [NSNumber numberWithFloat:M_PI];
    tranformAnimation.cumulative = YES;
    tranformAnimation.removedOnCompletion = YES;
    
    CAAnimationGroup*animaGroup = [CAAnimationGroup animation];
    animaGroup.animations = @[moveAnimation,scaleAnimation,tranformAnimation];
    animaGroup.duration = 2.f;

可以经由过程改变animationWithKeyPath来改更改画:
 CGPoint oldAnchorPoint =  _homeBtn.layer.anchorPoint;
    _homeBtn.layer.anchorPoint = CGPointMake(0.5, 0);
     [_homeBtn.layer setPosition:CGPointMake(_homeBtn.layer.position.x + _homeBtn.layer.bounds.size.width * (_homeBtn.layer.anchorPoint.x - oldAnchorPoint.x), _homeBtn.layer.position.y + _homeBtn.layer.bounds.size.height * (_homeBtn.layer.anchorPoint.y - oldAnchorPoint.y))];
    
    
    CABasicAnimation*shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    
    shakeAnimation.duration = 0.07;
    shakeAnimation.autoreverses = YES;//当你设定则个属性为 YES 时,在它达到目标地之后,动画的返回到开端的值,代替了直接跳转到 开端的值。
    shakeAnimation.repeatCount = 2;
    shakeAnimation.removedOnCompletion = NO;
    shakeAnimation.fromValue = http://www.sjsjw.com/100/000077MYM008781/[NSNumber  numberWithFloat:-0.05];
    shakeAnimation.toValue = [NSNumber  numberWithFloat:0.05];
    
    [self.homeBtn.layer addAnimation:shakeAnimation forKey:@"shakeAnimation"];

transform.scale = 比例轉換


    transform.scale.x = 闊的比例轉換
    transform.scale.y = 高的比例轉換
    transform.rotation.z = 平面圖的旋轉
    opacity = 透明度
    margin
    zPosition
    cornerRadius    圆角
    borderWidth
    bounds
    contents
    contentsRect
    cornerRadius
    frame
    hidden
    masksToBounds
    opacity
    position
    shadowColor
    shadowOffset
    shadowOpacity
    shadowRadius


58同城客户端,tabbar的点击的动画效不雅,就可以经由过程设置CABasicAnimation属性来做,小我花了一个小时的时光搞定,证实完全可以实现,

相关案例查看更多