이것은 본질적으로 여기에 게시 된 질문과 같습니다 : Animating a custom property in a CALayer 1 년 전 이상 답변되지 않았습니다.Monotouch에서 CoreAnimation을 사용하여 사용자 지정 속성에 애니메이션을 적용 하시겠습니까?
사용자 지정 레이어를 만들고 그 위에 원을 그립니다. 원의 반경을 애니메이트 할 수 있기를 원합니다 (나중에 다른 속성들). 내가 읽은 바로는 이렇게 설정했습니다 :
public class CircleLayer : CALayer
{
//[Export("radius")]
//public float Radius { get;set; }
//EDIT: I've now changed the radius field to what is coded below
public float Radius;
[Export("radius")]
public float getRadius()
{
return Radius;
}
[Export("setRadius:")]
public void setRadius(float val)
{
Radius = val;
}
public float Thickness {get;set;}
public CGColor Color {get;set;}
public float GlowAmount {get;set;}
private SizeF GlowOffset {get;set;}
[Export ("needsDisplayForKey:")]
static bool NeedsDisplayForKey (NSString key)
{
Console.WriteLine(key.ToString());
if(key.Equals("radius"))
{
return true;
}
else
return false;
}
public CircleLayer()
{
if(GlowAmount == 0.0f)
GlowAmount = 10f;
GlowOffset = new SizeF(0f,0f);
//CALayer.NeedsDisplayForKey("radius");
}
public override void DrawInContext (CGContext context)
{
base.DrawInContext (context);
Console.WriteLine("drawing...........");
PointF centerPoint = new PointF(125,125);//this.Frame.Width/2,this.Frame.Height/2);
//Outer circle
context.AddEllipseInRect(new RectangleF(centerPoint.X - Radius,
centerPoint.Y - Radius,
Radius * 2,
Radius * 2));
//Inner circle
context.AddEllipseInRect(new RectangleF(centerPoint.X - InnerRadius,
centerPoint.Y - InnerRadius,
InnerRadius * 2,
InnerRadius * 2));
//Fill in circle
context.SetFillColor(Color);
context.SetShadowWithColor(GlowOffset,GlowAmount,GlowColor);
context.EOFillPath();
}
}
그러나 작동하지 않습니다. NeedsDisplayForKey가 호출 될 때보고 된 반경 키를 절대로 얻지 못합니다.
편집 : 이제 SetValueForKey를 사용하여 Radius 속성의 값을 성공적으로 수정할 수 있습니다. 이 작업을 수행하면 SetNeedsDisplay()를 호출하여 화면을 업데이트해야하지만 애니메이션을 전혀 작동시키지 못합니다.
편집 # 2 : 첨부 된 샘플 : http://dl.dropbox.com/u/8617393/GraphicsTest1.zip
전체 샘플을 게시 하시겠습니까? –
안녕하세요, 응답 해 주셔서 감사합니다. 질문을 편집하여 샘플 프로젝트에 대한 링크를 포함했습니다. – Dermot