ios - 如何在 UIImageView 中快速显示带有动画的图像

标签 ios xcode swift animation

我正在使用 swift 从照片库加载图像。并将该图像添加到 UIImageView 上。我想通过运行下面的代码来显示动画图像,但它没有任何效果。选择后会立即显示图像。有谁知道在这种情况下我应该使用什么?

func imagePickerController(_picker: UIImagePickerController,
    didFinishPickingMediaWithInfo info: [String : AnyObject]){
        imagePicker.dismissViewControllerAnimated(true, completion: nil);
        self.photoView.alpha = 0;
        self.photoView.image = info[UIImagePickerControllerOriginalImage] as? UIImage;
        UIImageView.animateWithDuration(1, animations: {
            self.photoView.alpha = 1;
        });
}

最佳答案

你可以试试下面的代码

self.photoView.hidden = true;
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.ShowHideTransitionViews, animations: { () -> Void in
     self.photoView.hidden = false
     }, completion: { (Bool) -> Void in    }
)

您可以在动画 block 中添加要设置动画的 View 。

编辑

self.photoView.alpha = 0
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.ShowHideTransitionViews, animations: { () -> Void in
     self.photoView.alpha = 1
     }, completion: { (Bool) -> Void in    }
)

改变alpha值来创建动画效果

关于ios - 如何在 UIImageView 中快速显示带有动画的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35084443/

相关文章:

javascript - ios 状态栏 phonegap/cordova 的黑色文本颜色

objective-c - 在没有 ViewController 的情况下制作应用程序时如何使用 RootViewController?

ios - 每次单击按钮时将 UIButton 旋转 90 度

ios - 来自 UITableView 的 deleteRowsAtIndexPaths :withRowAnimation: 的不规则动画

ios - 自定义 UIButton - IBAction 不工作

ios - [FIRApp configure] 是否在 iOS 上以 DEBUG 模式发送统计信息?

ios - 不允许 webView 在 Swift 上播放声音

ios - 查询 Firebase iOS 最有效的方法

ios - 从主机获取 ping 延迟

swift - 动态调整自定义 xib 单元格的大小