1
简单的要求,但证明棘手。monotouch获取图像在屏幕上移动
下面的代码示例代码放在一起作为示例,我的最终目标是生成一个例程,使图像在给定x坐标上反弹。然而目前我只是第二次让事情继续前进而停滞不前。 下面的动画只发生一次,即无论From和To参数如何都无法上下移动。它仅在加载时移动一次,即
private void LoadGetStarted() {
UIImageView imageView = new UIImageView();
UIImage getStartedImage = new UIImage("images/DownArrow.gif");
float leftPos = 80f;
RectangleF f2 = new RectangleF(leftPos,
130f,
200f,
181f);
imageView.Image = getStartedImage;
imageView.Frame = f2;
this.Add(imageView);
Animate(imageView,"y",-100f,-200f);
Animate(imageView,"y",-100f,200f);
Animate(imageView,"y",10,100f);
}
private void Animate(UIImageView imageView,string type,float top, float bottom) {
var theAnimation = CABasicAnimation.FromKeyPath("transform.translation."+type);
theAnimation.Duration = 3;
theAnimation.Speed = 2;
theAnimation.FillMode = CAFillMode.Both;
theAnimation.From = NSNumber.FromFloat(top);
theAnimation.To = NSNumber.FromFloat(bottom);
theAnimation.RemovedOnCompletion = false;
imageView.Layer.AddAnimation(theAnimation,"imageView");
}