TableView在Swift 2中旋转垂直图像

时间:2016-03-11 21:19:08

标签: ios swift uitableview uiimage

我有2个观点。一个是具有自定义单元格的TableView(图像和标签),第二个是添加数据。我实施了从图书馆拍照/选择一个。如果图像比较宽,TableView会自动将其旋转90度。

我从来没有遇到过这个问题,任何想法导致了什么?

这是我保存图片的方式:

func saveImageAndCreatePath(image: UIImage) -> String {
        let imgData = UIImagePNGRepresentation(image)
        let imgPath = "image\(NSDate.timeIntervalSinceReferenceDate()).png"
        let fullPath = documentsPathforFileName(imgPath)
        imgData?.writeToFile(fullPath, atomically: true)
        return imgPath
    }

1 个答案:

答案 0 :(得分:1)

从这里下载UIImage + fixOrientation.h和UIImage + fixOrientation.m文件:https://www.dropbox.com/sh/gin2valk9pg4rmq/AABK7aN-ce3r9aTa4Z-e8nF3a?dl=0。将这两个文件添加到您的项目中,Xcode将询问您是否要创建桥接标题。选择是,然后在该桥接标题中添加

#import "UIImage+fixOrientation.h"

现在,您可以在代码中使用它,如下所示:

fixedImage = image.fixOrientation()

请记住,您可以在Swift代码中使用Objective-C文件: How to import Objective-C code into Swift from the same target