swif开发笔记12-Animations

//cell的动画出现

 

        tableView.reloadData()

        let cells = tableView.visibleCells

        let height = tableView.bounds.size.height

        // 将所有的cell平移到屏幕底部

        for cell in cells {

            cell.transform = CGAffineTransform.init(translationX: 0, y: height)

        }

        // cell动画回到正确位置

        var index = 0

        for cell in cells {

            UIView.animate(withDuration: 1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {

                cell.transform = CGAffineTransform.init(translationX: 0, y: 0)

            }, completion: nil)

            index += 1

        }

 

// 旋转动画

CGAffineTransform.init(rotationAngle:CGFloat.pi)

 

// 画圆

func huaYuan() -> UIView {

    let circlePath = UIBezierPath.init(arcCenter: CGPoint.init(x: 100, y: 500), radius: CGFloat.init(20), startAngle: CGFloat.init(0), endAngle: CGFloat.init(CGFloat.pi.native*2), clockwise: true)

    let shapeLayer = CAShapeLayer.init()

    shapeLayer.path = circlePath.cgPath

    shapeLayer.fillColor = UIColor.red.cgColor

    shapeLayer.strokeColor = UIColor.red.cgColor

    shapeLayer.lineWidth = 3.0

    

    let view = UIView.init()

    view.layer.addSublayer(shapeLayer)

    return view

}

// 指定动画轨迹

        // 指定点

        var firstPoint = yuanView.center

        firstPoint.y -= 100

        var secondPoint = firstPoint

        secondPoint.x += 40

        secondPoint.y -= 125.0;

        var endPoint = firstPoint

        endPoint.x += 40

        endPoint.y += 100

        

        let path = UIBezierPath.init()

        path.move(to: self.yuanView.center)

        path.addCurve(to: endPoint, controlPoint1: firstPoint, controlPoint2: secondPoint)

        // 动画

        let anima = CAKeyframeAnimation.init(keyPath: "position")

        anima.path = path.cgPath

        anima.duration = self.duration

        self.yuanView.layer.add(anima, forKey: "animate position along path")

        self.yuanView.center = endPoint

// 指定变大变小

        let currentFrame = self.myView.frame

        let firstFrame = currentFrame.insetBy(dx: -30, dy: -10)

        let secodeFrame = firstFrame.insetBy(dx: 50, dy: 30)

        let thirdFrame = secodeFrame.insetBy(dx: -10, dy: -20)

// 等比例变大变小

CGAffineTransform.init(scaleX: CGFloat.init(self.scale), y: CGFloat.init(self.scale))

CGAffineTransform.identity// 复原frame

原文地址:https://www.cnblogs.com/dengchaojie/p/7382453.html