簡體   English   中英

iOS:通過CATransform3DRotate旋轉時跳轉uiview

[英]iOS: jumping uiview when rotating via CATransform3DRotate

我嘗試使用自己的錨點以90度的角度旋轉uiview(高度和寬度為100)。 更改錨點后,我將轉換視圖,以便兩個更改相互抵消。

當我使用(Double.pi)旋轉視圖時,它會按預期進行動畫處理,但是當我更改為(Double.pi / 2)時,視圖就會跳起來。

    testView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
    testView.layer.transform = CATransform3DMakeTranslation(0, -50, 0)

    UIView.animate(withDuration: 2.3, delay: 0, options: .curveLinear, animations: { () -> Void in
        var allTransofrom = self.testView.layer.transform
        var c3d = CATransform3DIdentity
        c3d.m34 = 2.5 / (2000)
        let rot = CATransform3DRotate(c3d, CGFloat(Double.pi/2), 1, 0, 0)
        allTransofrom = CATransform3DConcat(allTransofrom, rot)
        self.testView.layer.transform = allTransofrom
    }, completion: {(finished) in
    } )

完整的代碼在這里

我自己能夠找到解決方案,但我仍然不知道跳躍的來源。

與其通過CGAffineTransform.translatedBy或CATransform3DMakeTranslation進行翻譯,我只是修改了我的NSLayoutConstraint。

testViewAnchors[0].constant = testViewAnchors[0].constant + CGFloat(50)

在我的情況下,不需要為“翻譯”制作動畫,但是由於可以對NSLayoutConstraints進行動畫處理,所以這不是問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM