gpt4 book ai didi

ios - TableView在Swift 2中旋转垂直图像

转载 作者:可可西里 更新时间:2023-11-01 02:17:22 26 4
gpt4 key购买 nike

我有两个观点。一种是带有自定义单元格(图像和标签)的 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
}

最佳答案

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

#import "UIImage+fixOrientation.h"

现在您将能够像这样在您的代码中使用它:

fixedImage = image.fixOrientation()

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

关于ios - TableView在Swift 2中旋转垂直图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35950113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com