Cocoa touch 以CAShapeLayer作为遮罩的UIView子类未正确设置动画

Cocoa touch 以CAShapeLayer作为遮罩的UIView子类未正确设置动画,cocoa-touch,uikit,xamarin.ios,cashapelayer,Cocoa Touch,Uikit,Xamarin.ios,Cashapelayer,我通过添加图层蒙版,将圆角添加到子类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));

我通过添加图层蒙版,将圆角添加到子类
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
属性。设置边框可调整遮罩以保持圆角的形状

但是,如果设置帧大小更改的动画,则会立即将遮罩设置为动画的目标值


有没有办法使我的视图检测到它是动画的一部分,并使遮罩正确地设置动画?

这就是CoreAnimation对显式动画的工作方式

使用显式动画,您永远不会实际更改原始对象的值,而只是在表示层中为对象设置动画。因此,在开始动画之前,您需要确保对象已经设置好,并使用最终想要的值


关于如何解决这类问题的完整解释,请参见WWDC 2011在线视频中的“核心动画要点”。查找第421课时

我看了视频。我没有使用显式动画。我正在调整UIView的属性,这会导致图层属性的更改,而这不会设置动画。我尝试为UIView的层设置动画,但没有成功:支持UIView的层从未设置动画。不过,我可以使用隐式动画设置CAShapeLayer的动画,但同时也可以设置UIView的动画。我在这里迷路了…我怎么能把两者结合起来呢?