swift3 - Multiple Animated Transitions in Swift -
i have nested uistackview holds uiimageviews. want each uiimageview flip progressively reveal single large uiimageview. code shows single view, there no animation it...it shows immediately. can't figure out why there isn't cascading effect on few seconds.
newimage full screen image.
imagearray randomized array of smaller images should flipping disappear.
private func flipimage(newimage: uiimage, imagearray: [uiimageview]) { let randomimage = imagearray.first! let abscoordinates = randomimage.convert(self.view.frame, to: super.view) let absframe = cgrect(x: abscoordinates.origin.x, y: abscoordinates.origin.y, width: randomimage.frame.width, height: randomimage.frame.height) if let croppedimage = newimage.cgimage?.cropping(to: absframe) { let croppedimageview = uiimageview(frame: absframe) croppedimageview.image = uiimage(cgimage: croppedimage) croppedimageview.ishidden = true self.view.addsubview(croppedimageview) let transitionoptions: uiviewanimationoptions = [.transitionflipfromtop, .showhidetransitionviews] uiview.transition(with: croppedimageview, duration: 1, options: transitionoptions, animations: { croppedimageview.ishidden = false if imagearray.count > 1 { var newarr = imagearray newarr.removefirst() self.flipimage(newimage: newimage, imagearray: newarr) } }) } }
i think want call your
self.flipimage(newimage: newimage, imagearray: newarr)
in completion of transition so:
uiview.transition(with: croppedimageview, duration: 1, options: transitionoptions, animations: { croppedimageview.ishidden = false }, completion { _ in if imagearray.count > 1 { var newarr = imagearray newarr.removefirst() self.flipimage(newimage: newimage, imagearray: newarr) } } )
this flip next image after first done.
if dont want wait until transition done can add delay before call next image flip:
uiview.transition(with: croppedimageview, duration: 1, options: transitionoptions, animations: { croppedimageview.ishidden = false if imagearray.count > 1 { var newarr = imagearray newarr.removefirst() self.perform(#selector(self.flip(_:)), with: [newimage, newarr], afterdelay: 0.5) } } ) func flip(_ data: array<any>) { self.flipimage(newimage: data[0], imagearray: data[1]) // give errors , needs "as! something" }
Comments
Post a Comment