0
func cubeTransition(label label:UILabel, text: String, direction:AnimationDirection) {

    //1
    let auxLabel = UILabel(frame: label.frame)

    auxLabel.text = text
    auxLabel.font = label.font
    auxLabel.textAlignment = label.textAlignment
    auxLabel.textColor = label.textColor
    auxLabel.backgroundColor = label.backgroundColor

    //2
    let auxLabelOffset = CGFloat(direction.rawValue) * label.frame.size.height/2.0

    auxLabel.transform = CGAffineTransform(scaleX: 1.0, y: 0.1).concatenating( CGAffineTransform(translationX: 0.0, y: auxLabelOffset))

    label.superview!.addSubview(auxLabel)

    //3
    UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseOut, animations: {


        auxLabel.transform = .identity

        label.transform = CGAffineTransform(scaleX: 1.0, y: 0.1).concatenating( CGAffineTransform(translationX: 0.0, y: -auxLabelOffset))

    }, completion: {_ in

        label.text = auxLabel.text
        label.transform = .identity
        auxLabel.removeFromSuperview()

    })
}

There is a line of code in this sample, which is " auxLabel.transform = .identity" What does this mean? I am quite confused, thanks in advance.

Hamish
  • 78,605
  • 19
  • 187
  • 280
Nan
  • 496
  • 3
  • 21
  • 3
    Have you looked at the relevant documentation for it? What part, specifically, isn't clear? – rmaddy Apr 23 '17 at 16:18
  • I did. The document says, the identity transform, which is quite confusing...and what exactly this line of code's function in this sample? – Nan Apr 23 '17 at 16:21
  • 2
    In linear algebra the identity matrix applies no transformation to another matrix or vector. So in this case, the transform has no effect when you set it to .ideentity. Something like 1x = x – DanielEdrisian Apr 23 '17 at 17:45

0 Answers0