Is it possible to setup UIImageView to handle image orientation? When I set the UIImageView to image with orientation RIGHT (it is photo from camera roll), the image is rotated to right, but I want to show it in proper orientation, as it was taken.

I know I can rotate image data but it is possible to do it more elegant?

推荐答案

If I understand, what you want to do is disregard the orientation of the UIImage? If so then you could do this:

UIImage *originalImage = [... whatever ...];

UIImage *imageToDisplay =
     [UIImage imageWithCGImage:[originalImage CGImage]
              scale:[originalImage scale]
              orientation: UIImageOrientationUp];

So you're creating a new UIImage with the same pixel data as the original (referenced via its CGImage property) but you're specifying an orientation that doesn't rotate the data.

Ios相关问答推荐

Swift导航远离视频导致崩溃

设置托管在DigitalOcean上的iOS通用链接

Flutter 翼项目.升级到XCode 15.0.1`pod install`抛出错误FlutterMacOS.podspec.json 3.13.2的ParserError

在 Android 和 iOS 应用程序上下文中阻止后台线程有哪些缺点?

无法使用 NavigationView 和 NavigationLink 在 SwiftUI 中弹出当前屏幕

UIView 阴影不适用于自定义扩展

ITMS-90725 无用的错误信息,因为它自相矛盾,苹果上传

Flutter firebase_auth 中的无效应用程序凭据/令牌不匹配

更改图标会导致 SwiftUI 动画出现故障?

Swiftui为什么在点击第二行之前背景不起作用

无法结合 UIImageView 旋转动画和 tableView 部分重新加载

UICollectionView 添加 UICollectionCell

将自定义对象保存到 NSUserDefaults

命令 /Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang 失败,退出代码为 1

Xcode / iOS模拟器:手动触发重大位置更改

如何在 Objective-C 中组合两个数组?

在 UITableViewController 中使用 UISearchDisplayController 时断言失败

使用 xib 创建可重用的 UIView(并从情节提要中加载)

/usr/bin/codedesign 失败,退出代码为 1

未找到符号:kUTTypeImage