如何使用Swift水平翻转UIImage? [英] How to flip UIImage horizontally with Swift?

查看:481
本文介绍了如何使用Swift水平翻转UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进行UIImage翻转的解决方案是使用Objective-C代码:

The solution to do UIImage flipping is with the Objective-C code:

[UIImage imageWithCGImage:img.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored]

但是,在Swift中没有imageWithCGImage!是否有使用Swift水平翻转图像的解决方案?谢谢!

However, imageWithCGImage is not available in Swift! Is there a solution for flipping image horizontally with Swift? Thanks!

推荐答案

大多数工厂方法都在swift中转换为初始值设定项。只要可用,即使类方法仍然可用,它们也是首选。您可以使用:

Most factory methods are converted to initializers in swift. Whenever available, even if the class method is still available, they are preferred. You can use:

    init(CGImage cgImage: CGImage!, scale: CGFloat, orientation: UIImageOrientation)

使用情况如下:

var image = UIImage(CGImage: img.CGImage, scale: 1.0, orientation: .DownMirrored)

这篇关于如何使用Swift水平翻转UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆