CGAffineTransform无效后自动调整子视图

时间:2015-11-27 11:41:08

标签: ios iphone swift uiview

我在应用两个转换后调整子视图的大小有问题:CGAffineTransformMakeRotation和CGAffineTransformScale。

A screenshot that represents the problem.

如您所见,#1是包含子视图#2的卡片视图。应用两个转换后(拖动时),子视图未正确调整大小。

请参阅下文,了解CardView中使用的代码:

/**
 * This code is placed within the CardView class 
 * in the touchedMoved:touches:withEvent method.
 */

// Dictates the rotation strength based on the distance from center and card width.
let rotationStrength = min(self.distanceFromCenter.x / CGRectGetWidth(self.bounds), CardView.rotationMax)

// Degree change in radians.
let rotationAngle = CardView.rotationAngle * rotationStrength

// Amount the height/width changes when you move the card up to a certain point.
let scaleStrength = 1 - ((1 - CardView.scaleMin) * fabs(rotationStrength))
let scale = max(scaleStrength, CardView.scaleMin)

// Transformation to rotate by certain amount.
let rotationTransform = CGAffineTransformMakeRotation(rotationAngle)

// Transformation to scale by a certain amount.
let scaleAndRotationTransform = CGAffineTransformScale(rotationTransform, scale, scale)

// Apply transformations.
self.transform = scaleAndRotationTransform

我已经尝试了许多可能的解决方案:

  1. .xib文件中的预定义约束,其中子视图#2具有与其超级视图#1相同的宽度,高度,顶部和前导。
  2. 以编程方式设置子视图#2的宽度,高度,顶部和前导约束,其中translatesAutoresizingMaskIntoConstraints为false。
  3. 以编程方式将autoresizingMask设置为FlexibleWidth和FlexibleHeight。
  4. 有什么建议吗?我有点卡在这里! :)

0 个答案:

没有答案