How do I rotate an image on the iPhone?

眉间皱痕 提交于 2019-12-23 04:11:51

问题


How do I rotate an image in iPhone programming?


回答1:


A great rotation and image UIImage category by Allen Brunson can be found here: http://www.platinumball.net/blog/2010/01/31/iphone-uiimage-rotation-and-scaling/




回答2:


image.transform = CGAffineTransformMakeRotation(3.142);

rotates it 180 degrees.




回答3:


You can rotate a view using a CCGAffineTransform. You can create a rotation matrix by specifying the degrees in radians you want to rotate, then setting the rotation matrix to be the .transform property of your view.




回答4:


//If someone needs in swift 3 



    func rotateImageClockWise(theImage: UIImage,imageView:UIImageView) -> UIImage {

        var orient: UIImageOrientation!
        let imgOrientation = theImage.imageOrientation


        UIView.transition(with: imageView, duration: 0.2, options: .transitionCrossDissolve, animations: {() -> Void in

            switch imgOrientation {

            case .left:
                orient = .up

            case .right:
                orient = .down

            case .up:
                orient = .right

            case .down:
                orient = .left

            case .upMirrored:
                orient = .rightMirrored

            case .downMirrored:
                orient = .leftMirrored

            case .leftMirrored:
                orient = .upMirrored

            case .rightMirrored:
                orient = .downMirrored
            }


        }, completion: { _ in })

        let rotatedImage = UIImage(cgImage: theImage.cgImage!, scale: 1.0, orientation: orient)
        return rotatedImage
    }
//Just call the method like this :

rotateImageClockWise(theImage: UIImage,imageView:UIImageView)


来源:https://stackoverflow.com/questions/955635/how-do-i-rotate-an-image-on-the-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!