Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 快速缩小动画_Ios_Swift - Fatal编程技术网

Ios 快速缩小动画

Ios 快速缩小动画,ios,swift,Ios,Swift,我正在尝试为UIImageView制作一些动画(仅缩小) 1-我将框架设置为大于屏幕,使其放大如下: private lazy var imageView: UIImageView = { let image = UIImageView() image.frame = CGRect(x: 0, y: 0, width: view.frame.width + 300, height: view.frame.height + 300) image.center = view.

我正在尝试为UIImageView制作一些动画(仅缩小)

1-我将框架设置为大于屏幕,使其放大如下:

private lazy var imageView: UIImageView = {
    let image = UIImageView()
    image.frame = CGRect(x: 0, y: 0, width: view.frame.width + 300, height: view.frame.height + 300)
    image.center = view.center
    image.image = UIImage(named: "1111")
    image.contentMode = .scaleAspectFill
    return image
}()
func firstAnimation() {
    UIView.animate(withDuration: 15, animations: {

        // HERE 
        self.imageView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)

    }) { (finished) in
        self.secondAnimation()
    }
}
我想让画面恢复到屏幕大小,如下所示:

private lazy var imageView: UIImageView = {
    let image = UIImageView()
    image.frame = CGRect(x: 0, y: 0, width: view.frame.width + 300, height: view.frame.height + 300)
    image.center = view.center
    image.image = UIImage(named: "1111")
    image.contentMode = .scaleAspectFill
    return image
}()
func firstAnimation() {
    UIView.animate(withDuration: 15, animations: {

        // HERE 
        self.imageView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)

    }) { (finished) in
        self.secondAnimation()
    }
}
不幸的是,我没有和我一起工作

下面是完整的类代码:

Swift 4+ 使用
CGAffineTransform.identity
将图像调整为第一个
identity

UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: {
        
       // HERE
       self.imageview.transform = CGAffineTransform.identity.scaledBy(x: 2, y: 2) // Scale your image

 }) { (finished) in
     UIView.animate(withDuration: 1, animations: {
       
      self.imageview.transform = CGAffineTransform.identity // undo in 1 seconds

   })
}
放大代码:

[UIView animateWithDuration:1.0动画:^{
imgv.transform=CGAffineTransformMakeScale(1.0,1.0);
}完成:^(布尔完成){
}];
缩小的代码:

[UIView animateWithDuration:1.0动画:^{
imgv.transform=CGAffineTransformMakeScale(0.1,0.1);
}完成:^(布尔完成){
imgv.transform=CGAffineTransformMakeScale(.0,.0);
}];

这里的
imvv
是我的
UIImageview
对象。可以将其替换为视图对象。在
缩小
代码中,我们通过
缩放
将视图隐藏到
0

我只需要将其缩小即可查看
extension UIView {
      UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseIn, animations: {
          self.transform = CGAffineTransform.identity.scaledBy(x: 1.1, y: 1.1)
      }) { (finished) in
          UIView.animate(withDuration: 1, animations: {
          self.transform = CGAffineTransform.identity
      })
}