0

UIView我通过添加图层蒙版为我的子类添加了圆角。以下是 Montouch 代码,但在 ObjC 中也应该很容易理解其含义:

// Add a layer that holds the rounded corners.
UIBezierPath oMaskPath = UIBezierPath.FromRoundedRect (this.Bounds, this.eRoundedCorners, new SizeF (this.fCornerRadius, this.fCornerRadius));

private void UpdateMask()
{           
if(this.Layer.Mask == null)
{
    CAShapeLayer oMaskLayer = new CAShapeLayer ();
    oMaskLayer.Frame = this.Bounds;

    // Set the newly created shape layer as the mask for the image view's layer
    this.Layer.Mask = oMaskLayer;
}
((CAShapeLayer)this.Layer.Mask).Path = oMaskPath.CGPath;
}

我已经超载了Frame财产。设置框架会调整蒙版以保持圆角的形状。

但是,如果我对帧大小的变化进行动画处理,则掩码会立即设置为动画的目标值。

有没有办法让我的视图检测到它是动画的一部分并使蒙版正确动画?

4

1 回答 1

1

这就是 CoreAnimation 用于显式动画的方式。

使用显式动画,您永远不会真正改变原始对象的值,您只是在表示层中为对象设置动画。所以你需要确保你的对象在你开始动画之前已经设置好了,你最终想要的值是多少。

关于如何解决这类问题的完整说明在 WWDC 2011 在线视频的“Core Animation Essentials”中进行了解释。查找会话 421

于 2012-02-19T18:53:42.270 回答