How to rotate an image 90 degrees on iOS?(如何在 iOS 上将图像旋转 90 度?)
问题描述
我想做的是从我的相机拍摄快照,将其发送到服务器,然后服务器将图像发送回 viewController 上.如果图像处于纵向模式,则图像在屏幕上显示良好,但是如果图像是在横向模式下拍摄的,则图像在屏幕上会出现拉伸(因为它试图以纵向模式出现!).我不知道如何解决这个问题,但我想一个解决方案是首先检查图像是否处于纵向/横向模式,然后如果它处于横向模式,则将其旋转 90 度,然后再将其显示在屏幕上.那我该怎么做呢?
What I want to do is take a snapshot from my camera , send it to a server and then the server sends me back the image on a viewController. If the image is in portrait mode the image appears well on screen , however if the image was taken in landscape mode the image appears streched on the screen(as it tries to appear on portrait mode!). I dont know how to fix this but i guess one solution is first to check if the image is in portrait/landscape mode and then if it is on landscape mode rotate it by 90degrees before showing it on screen. So how could i do that?
推荐答案
self.imageview.transform = CGAffineTransformMakeRotation(M_PI_2);
Swift 4+:
self.imageview.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi/2))
这篇关于如何在 iOS 上将图像旋转 90 度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 上将图像旋转 90 度?


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01