xamarin.ios - monotouch Get Image to move around the screen -
simple requirement proving tricky.
the sample code below threw example, end goal produce routine makes image bounce on given x co-ordinate. @ moment i'm stuck on getting thing move second time. animation below happens once i.e cannot move , down regardless of , parameters. moves once when loaded, i.e.
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"); }
that because adding animations layer animate same property, while previous animation has not yet completed. try adding next animation when previous animation completes hooking cabasicanimation.animationstopped
event. not forget set from
value previous to
value next animation continues last 1 completed. also, set removedoncompletion
true
don't stack completed animations not need in layer
.
Comments
Post a Comment