imjonu
imjonu

Reputation: 515

Transform a Image in Swift 3

So I have this simple problem where I need to rotate a CALayer 90 degrees. The problem is however, that it seems none of the methods I have found from research actually do anything. Below is the code I am using where imgLayer is a CALayer

var transform = CATransform3DIdentity
transform = CATransform3DRotate(transform, (CGFloat(Double.pi/2)), 0, 1, 0)
imgLayer.transform = transform

From what I have read this code should work but it does not seem to have any affect at all and I was wondering whether anyone had any suggestions as to why this is the case. Any help on the topic would be greatly appreciated, thank you.

Regards, Nick

Upvotes: 0

Views: 946

Answers (1)

Okan
Okan

Reputation: 410

You can first set your image in imageView and rotate get your image in imageView

Here:

    let customImageView = UIImageView()
    customImageView.frame = CGRect.init(x: 0, y: 0, w: 250, h: 250)
    customImageView.image = UIImage(named: "yourImage")

    customImageView .transform = customImageView .transform.rotated(by: CGFloat.init(M_PI_2))
    var rotatedImage = UIImage()
    rotatedImage = customImageView.image!

Upvotes: 1

Related Questions