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");
}