skip to Main Content

I will try with this code, but not work

let contentMode: UIView.ContentMode = imageView.contentMode == .scaleAspectFill ?
.scaleAspectFit : .scaleAspectFill
 
 UIView.animate(withDuration: 0.5) {
     self.imageView.contentMode = contentMode
 }

3

Answers


  1. Chosen as BEST ANSWER

    I'm done this with help of transition

    let contentMode: UIView.ContentMode = imageView.contentMode == .scaleAspectFill ? .scaleAspectFit : .scaleAspectFill
            UIView.transition(with: imageView, duration: 0.5, options: .transitionCrossDissolve, animations: {
                    self.imageView.contentMode = contentMode
                })
    

  2. You can’t do it. This is not an animatable property. It is unclear what kind of animation would even make sense.

    An alternative would be to substitute a second image view with a different content mode, and cross-dissolve from one image view to the other (transformation).

    Login or Signup to reply.
  3. Why don’t you just animate UIImageView itself? The code below is an example for growing animation.

        let height = imageView.frame.height
        let width = imageView.frame.width
        
        let x = imageView.frame.origin.x
        let y = imageView.frame.origin.y
                
        imageView.frame = CGRect(x: x, y: y, width: 0, height: 0)
        
        UIView.animate(withDuration: 0.5) {
            self.imageView.frame = CGRect(x: x, y: y, width: width, height: height)
        }
        
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search