Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift中使用滑动手势翻转x轴和y轴上的图像?_Ios_Swift - Fatal编程技术网

Ios 如何在swift中使用滑动手势翻转x轴和y轴上的图像?

Ios 如何在swift中使用滑动手势翻转x轴和y轴上的图像?,ios,swift,Ios,Swift,有谁能帮助我,如何用swift动画在x轴和y轴上使用滑动手势翻转图像。我找到了一些答案,但它们不符合我的要求。提前谢谢。您应该先尝试自己编写代码,如果代码不起作用,请将其粘贴到此处并询问问题所在。现在的问题太宽泛了。你应该先尝试自己编写代码,如果代码不起作用,请将其粘贴到这里,并询问出了什么问题。现在的问题太广泛了。这没有使用手势,但肯定会垂直和水平翻转图像。这没有使用手势,但肯定会垂直和水平翻转图像。 //MARK: - Image flipping operations perfor

有谁能帮助我,如何用swift动画在x轴和y轴上使用滑动手势翻转图像。我找到了一些答案,但它们不符合我的要求。提前谢谢。

您应该先尝试自己编写代码,如果代码不起作用,请将其粘贴到此处并询问问题所在。现在的问题太宽泛了。你应该先尝试自己编写代码,如果代码不起作用,请将其粘贴到这里,并询问出了什么问题。现在的问题太广泛了。这没有使用手势,但肯定会垂直和水平翻转图像。这没有使用手势,但肯定会垂直和水平翻转图像。
    //MARK: - Image flipping operations performed here.

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

            var orient: UIImageOrientation!
            let imgOrientation = theImage.imageOrientation

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

                switch imgOrientation {

                case .left:
                    orient = .rightMirrored

                case .right:
                    orient = .leftMirrored

                case .up:
                    orient = .upMirrored

                case .down:
                    orient = .downMirrored

                case .upMirrored
                    :
                    orient = .up

                case .downMirrored:
                    orient = .down

                case .leftMirrored:
                    orient = .right

                case .rightMirrored:
                    orient = .left
                }

            }, completion: { _ in })

            let mirroredImage = UIImage(cgImage: theImage.cgImage!, scale: 1.0, orientation: orient)
            return mirroredImage
        }

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

            var orient: UIImageOrientation!
            let imgOrientation = theImage.imageOrientation

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

                switch imgOrientation {

                case .left:
                    orient = .leftMirrored

                case .right:
                    orient = .rightMirrored

                case .up:
                    orient = .downMirrored

                case .down:
                    orient = .upMirrored

                case .upMirrored:
                    orient = .down

                case .downMirrored:
                    orient = .up

                case .leftMirrored:
                    orient = .left

                case .rightMirrored:
                    orient = .right
                }

            }, completion: { _ in })
            let mirroredImage = UIImage(cgImage: theImage.cgImage!, scale: 1.0, orientation: orient)
            //let mirroredImage = UIImage(CGImage: theImage.CGImage!, scale: 1.0, orientation: orient)
            return mirroredImage
        }

//MARK: To call the above function this can be done like this:

flipImageOnHorizontalAxis(theImage: imageView.image!, imageView: imageView)

or

flipImageOnVerticalAxis(theImage: imageView.image!, imageView: imageView)