繁体   English   中英

如何在iPhone上旋转图像?

[英]How do I rotate an image on the iPhone?

如何在iPhone编程中旋转图像?

可以在以下位置找到Allen Brunson出色的旋转和图像UIImage类别: http : //www.platinumball.net/blog/2010/01/31/iphone-uiimage-rotation-and-scaling/

image.transform = CGAffineTransformMakeRotation(3.142);

将其旋转180度。

//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)

您可以使用CCGAffineTransform旋转视图。 您可以通过指定要旋转的弧度数来创建旋转矩阵,然后将旋转矩阵设置为视图的.transform属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM