2012-02-19 60 views
0

我已通过添加图层掩码向我的子类UIView添加了圆角。以下是Montouch代码,但应该是很容易获得的意义也ObjC:以CAShapeLayer为掩码的UIView的子类不能正确动画

// 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财产。设置框架会调整蒙版以保持圆角的形状。

但是,如果我为框架大小的变化设置了动画效果,那么掩码会立即设置为动画的目标值。

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

回答

1

这是CoreAnimation如何工作的显式动画。

使用显式动画,您绝对不会实际更改原始对象的值,您只需为表示层中的对象设置动画。所以你需要确保你的对象已经设置好,然后用最后想要的值开始动画。

有关如何解决此类问题的完整说明,请参见WWDC 2011在线视频中的“Core Animation Essentials”。寻找会议421

+0

我看了视频。我没有使用明确的动画。我正在调整UIView的属性,这会导致图层属性的更改,而且不会生成动画。我试图为UIView的图层设置动画,但没有成功:支持UIView的图层从不动画。然而,我可以使用隐式动画来动画化CAShapeLayer,但同时也会动画UIView。我迷失在这里......我怎么能把两者结合起来? – Krumelur 2012-02-19 21:09:53