StoreSearch - Exercise to animate DetailView in iPad

I feel like this shouldnt be this hard. I think I get where it should be done, when we set the popUpView.isHidden to false. Im thinking that line goes into a completion but im stumped how i add the animation.

I’m looking for I guess a start then im hoping to figure out the rest myself unless i hit a wall haha… But any hints?

Thanks,
Chris

Not sure I am clear on the question…can you point to a page number for the exercise?

@oochr1soo nevermind, I see where you are, basically, you would want to start the transition where you set popupView.hidden to false

Thanks! So it would use a transition coordinator? That’s what i was thinking.

Chris

Yeah, that is what I did on the UIView and used a `.transitionCrossDissolve.

If you want to see the code I added, you can see at my repo at line 137: https://github.com/kickinbahk/swift-StoreSearch/blob/master/StoreSearch/DetailViewController.swift

If you implement it differently, I would be interested to see how you do it.

1 Like

Try putting self.popupView.alpha = 0 in the animations block and self.popupView.hidden = true; self.popupView.alpha = 1 in the completion block.

    UIView.animate(withDuration: 0.5, animations: {
        self.popupView.alpha = 0
        self.popupView.isHidden = true
    }, completion: { (finished) in
        self.popupView.isHidden = false
        self.popupView.alpha = 1
    })

So here is what i have but it never appears to fade in. It just sits there for 0.5 seconds and then boom it appears. But yet if i take out the alpha line in the completion it doesnt come back which i would expect. What am I missing?

Thanks,
Chris

Yeah I couldn’t get it to work that way. It would do the double appear like you described.

I used

    UIView.transition(with: view, duration: 0.5, 
                                options: .transitionCrossDissolve, 
                                animations: { _ in
        self.popupView.isHidden = false
    }, completion: { _ in })

That works perfect kickinbahk… Not really sure why it wont let me just do a simple fade in with the alpha setting?

@hollance: Any ideas why changing the alpha has no effect? It doesnt animate it, it just goes from 0 right to 1.

Ah, do i have to modify the transform identity or something like that?

Thanks,
Chris

I’m not sure. However, my suggestion was to put self.popupView.isHidden = true in the completion block, not in the animation block.

Wouldn’t self.popupView.isHidden = true in the completion block hide it? I would expect it should be false to be shown?

Ooooh, it seems I am not paying attention at all… :blush:

   self.popupView.isHidden = false
   self.popupView.alpha = 0
   UIView.animate(withDuration: 0.5, animations: {
        self.popupView.alpha = 1
    }, completion: { (finished) in
    })

You want to set isHidden to false and alpha to 0 before the animation starts. Inside “animations” you set alpha to 1, so that the animation will fade from alpha 0 to alpha 1 in 0.5 seconds.

1 Like

Ah there we go! That was my mistake, i was setting the alpha to 0 in the animations block then setting it back to 1 in the completion.

Thanks for the help!

Chris