zoukankan      html  css  js  c++  java
  • caanimationgroup与CATransaction的区别

    动画的组合;

    caanimationgroup:同一个layer;

    CATransaction:不同layer;

    In Core Animation, transactions are a way to group multiple animation-related changes together. Transactions ensure that the desired animation changes are committed to Core Animation at the same time:

    CATransaction.begin()
    
    backingLayer1.opacity = 1.0
    backingLayer2.position = CGPoint(x: 50.0, y: 50.0)
    backingLayer3.backgroundColor = UIColor.red.cgColor
    
    CATransaction.commit()
    

    UIView itself has a handful of functions involved with enabling and disabling animations, such as setAnimationsEnabled(_:) and performWithoutAnimation(_:). However, to ensure that both UIView-style and CALayer-style animations are suppressed, you can always just use CATransaction.

    https://www.calayer.com

    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

        rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];

        rotationAnimation.duration = 1;

        rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

        

        CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

        scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];

        scaleAnimation.duration = 1;

        scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

        

        CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

        animationGroup.duration = 1;

        animationGroup.autoreverses = YES;

        animationGroup.repeatCount = 1;

        animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil];

        [view.layer addAnimation:animationGroup forKey:@"animationGroup"];

    CATransaction.begin()

        CATransaction.setAnimationDuration(1.0)

        CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut))

        // Layer animation

        let myAnimation = CABasicAnimation(keyPath: "frame");

        myAnimation.toValue = NSValue(cgRect: myNewFrame)

        myAnimation.fromValue = NSValue(cgRect: myLayer.frame)

        myLayer.frame = myNewFrame

        myLayer.add(myAnimation, forKey: "someKeyForMyAnimation")

        // Outer animation

        let outerAnimation = CABasicAnimation(keyPath: "frame")

        outerAnimation.toValue = NSValue(cgRect: myNewOuterFrame)

        outerAnimation.fromValue = NSValue(cgRect: outerView.frame)

        outerView.layer.frame = myNewOuterFrame

        outerView.layer.add(outerAnimation, forKey: "someKeyForMyOuterAnimation")

        CATransaction.commit()

    //保证 insert row 不闪屏

            UIView.setAnimationsEnabled(false)

            CATransaction.begin()

            CATransaction.setDisableActions(true)

            self.beginUpdates()

            self.insertRows(at: rows, with: .none)

            self.endUpdates()

            self.scrollToRow(at: rows[0], at: .bottom, animated: false)

            CATransaction.commit()

            UIView.setAnimationsEnabled(true)

  • 相关阅读:
    docker 学习操作记录 4
    docker 学习操作记录 1
    centos 旧版本镜像
    zabbix 搭建 mysql 连接报错
    js判断是否为手机或是pc
    滚动翻页vue
    note
    Vue-cli 鼠标监听事件之滚动条
    adobe Keychain mac
    HTML协义代码
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10362366.html
Copyright © 2011-2022 走看看