ahmetvefa53
ahmetvefa53

Reputation: 611

UIView animate is not animating

I want to hide logo(Imageview) and show search bar by animately.But when code run to be hidden animations works immediately (it must be in 2 seconds).search bar is visible in 2 seconds by animately.what is wrong in this code?

  UIView.transition(with: self.logo, duration: 2, options: .transitionCrossDissolve, animations: {
            self.logo.isHidden = true
        }) { (completed) in
            UIView.transition(with: self.searchBar, duration: 2, options: .transitionCrossDissolve, animations: {
                self.searchBar.isHidden = false
            },completion: nil)
        }

Upvotes: 0

Views: 186

Answers (1)

velociraptor11
velociraptor11

Reputation: 604

As pointed in the comments , you need to use the alpha property to create an effect of appearance/disappearance. So your code will look something like:

UIView.transition(with: self.logo, duration: 2, options: .transitionCrossDissolve, animations: {
            self.logo.alpha = 0
        }) { (completed) in
            UIView.transition(with: self.searchBar, duration: 2, options: .transitionCrossDissolve, animations: {
                self.searchBar.alpha = 1
            },completion: nil)
        }

As stated in the apple docs here: https://developer.apple.com/documentation/uikit/uiview , the

The following properties of the UIView class are animatable: frame, bounds,center, transform,alpha , background colour

Upvotes: 1

Related Questions