ios - UIButton Animation in Swift -


i'm trying make animation on button upon button press. case following. button have have picture of apple. when pressed change image1, image2, image3 (like .gif) , picture of pear. right i'm seeing change apple pear , skipping on animation i'm trying create.

this code animation part:

    var image1:uiimage = uiimage(named: buttonanimationimage1)!;     var image2:uiimage = uiimage(named: buttonanimationimage2)!;     var image3:uiimage = uiimage(named: buttonanimationimage3)!;      sender.imageview!.animationimages = [image1, image2, image3];     sender.imageview!.animationduration = 1.5;     sender.imageview!.startanimating(); 

you can have behavior using animated images.

var image1:uiimage = uiimage(named: buttonanimationimage1)!; var image2:uiimage = uiimage(named: buttonanimationimage2)!; var image3:uiimage = uiimage(named: buttonanimationimage3)!; var images = [image1, image2, image3] var animatedimage = uiimage.animatedimagewithimages(images, duration: 1.5) sender.setimage(animatedimage, forstate: uicontrolstate.normal) 

the problem here animation continue forever. more, can't animated images number of times animation running. so, in order stop animation, after required time need change image of button again , set pear image.

the complete source code is:

// setting images conform animation var image1:uiimage = uiimage(named: buttonanimationimage1)!; var image2:uiimage = uiimage(named: buttonanimationimage2)!; var image3:uiimage = uiimage(named: buttonanimationimage3)!; var images = [image1, image2, image3] var animatedimage = uiimage.animatedimagewithimages(images, duration: 1.5) sender.setimage(animatedimage, forstate: uicontrolstate.normal)  // code setting pear image button after delay let delay = 1.3 * double(nsec_per_sec) let time = dispatch_time(dispatch_time_now, int64(delay)) dispatch_after(time, dispatch_get_main_queue()) {       sender.setimage(pearimage, forstate: .normal)  } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -