ios - Fade in a background view during custom animation transition -
i wanted add custom transition app , followed amazing answer found here.
it working great, wanted take step further. want have view on first page alpha 0 or hidden @ first fades in user swipes down between 2 pages. top view have transparent background appear though coming in background color. great example of mean can seen in snapchat, when swiping between pages seen in screen shot below.
the background becomes blue , when new view comes in solid blue.
i understand code has go in presentation controller stated in original question answer followed, unsure how implement this. also, when setting shouldremovepresentersview false crash here
func animatetransition(using transitioncontext: uiviewcontrollercontexttransitioning) { let inview = transitioncontext.containerview let toview = transitioncontext.view(forkey: .to)! let fromview = transitioncontext.view(forkey: .from)! }
i similar in app show image when gesture completed. fade image out in application, modified fade in minor change. in situation fade in or out image. using extension below, animatewithduration examples below might you. see code below:
public extension uiimage { func showandfadeout(atpoint point: cgpoint, sender:uiviewcontroller) { let buttonview = uiimageview(image: self) buttonview.center = point sender.view.addsubview(buttonview) uiview.animate(withduration: 3.0, delay: 0.0, options: .curveeaseout, animations: { buttonview.alpha = 0 }, completion: { finished in buttonview.removefromsuperview() }) } func showandfadein(atpoint point: cgpoint, sender:uiviewcontroller) { let buttonview = uiimageview(image: self) buttonview.center = point sender.view.addsubview(buttonview) buttonview.alpha = 0 uiview.animate(withduration: 3.0, delay: 0.0, options: .curveeasein, animations: { buttonview.alpha = 1 }, completion: { finished in buttonview.removefromsuperview() }) } }
you can use this:
image.showandfadein(atpoint: gestureendpoint, sender: self)
hopefully that's helpful. remove button in completion block if want view stay on screen, remove line of code.
Comments
Post a Comment