2017-09-22 66 views
0

所以我有這個簡單的問題,我需要將CALayer旋轉90度。然而,問題是,似乎我從研究中發現的方法實際上並沒有做任何事情。下面是我使用的代碼,其中imgLayer是CALayer的在Swift中轉換圖像3

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

從我讀這段代碼應該工作,但它似乎並沒有帶任何影響,我想知道是否有人有任何建議,爲什麼是這種情況。任何有關該主題的幫助將不勝感激,謝謝。

問候,尼克

+1

[你有沒有試過這種解決方案??](HTTPS: //stackoverflow.com/a/42943864) –

+0

你在y軸上旋轉。您可能想旋轉z軸。 –

+0

非常感謝Okan Yucel,您將我的解決方案與我完美結合! – imjonu

回答

1

你可以先設置ImageView的圖像和旋轉讓你的形象在ImageView的

這裏:

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!