簡體   English   中英

在CATransform3DRotate之后查看剪輯

[英]View clipping after CATransform3DRotate

我正在嘗試將透視變換應用於視圖(讓我們稱之為subview ),它只沿其框架繪制一個正方形,在其超視圖中水平居中,並且是其超視圖寬度的3/4: 在此輸入圖像描述

我正在使用這個片段:

var rotationAndPerspectiveTransform = CATransform3DIdentity
rotationAndPerspectiveTransform.m34 = CGFloat(-1.0/280.0)
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 30.0 * CGFloat.pi / 180.0, 1.0, 0.0, 0.0)
subview.layer.transform = rotationAndPerspectiveTransform

我需要哪種轉換,但有一個奇怪的效果 - 矩形的右邊部分是“剪裁”的:

在此輸入圖像描述

是什么造成的? 我怎么能避免呢?

謝謝!

啊,這是一個很好的舊邊界與框架問題。 變換后框架變寬,不再適合邊界。

因為我仍然希望它是水平居中的,所以這個剪輯做了訣竅:

let transformedFrame  = segmentView.layer.frame
let transformedBounds = segmentView.layer.bounds
let correctedBoundsX  = (transformedFrame.width - transformedBounds.width) / 2

segmentView.layer.bounds = CGRect(x: correctedBoundsX, y: transformedBounds.origin.y, width: transformedBounds.width, height: transformedBounds.height)

暫無
暫無

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

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