问题描述
我想做的是从我的相机拍摄快照,将其发送到服务器,然后服务器将图像发送回 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 度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!