user1951992
user1951992

Reputation:

Why are my transformations concatenating, rather than being replaced?

Ok, this is weird...

func closePageCell(cell : BookPageCell) {

    var transform = CATransform3DIdentity

    if cell.layer.anchorPoint.x == 0 {
        transform = CATransform3DRotate(transform, CGFloat(0), 0, 1, 0)
        transform = CATransform3DTranslate(transform, -0.7 * cell.layer.bounds.width / 2, 0, 0)
        transform = CATransform3DScale(transform, 0.7, 0.7, 1)
    }

    else {
        transform = CATransform3DRotate(transform, CGFloat(-M_PI), 0, 1, 0)
        transform = CATransform3DTranslate(transform, 0.7 * cell.layer.bounds.width / 2, 0, 0)
        transform = CATransform3DScale(transform, 0.7, 0.7, 1)
    }

    cell.layer.transform = transform
}

The transforms are concatenating here but the syntax is '='

Surely '=' replaces the transform. Why is this working ?!

Upvotes: 1

Views: 78

Answers (1)

Fonix
Fonix

Reputation: 11597

the CATransform3Dxxx takes in a transform as a parameter which you are feeding itself into, and returns it back. so each time the method is called it is building up the transform, effectively concatenating them together.

if you replaced the transform in the parameter with CATransform3DIdentity the behaviour you were expecting would happen

Upvotes: 5

Related Questions