ios - 如何快速使用滑动手势翻转 x 和 y 轴上的图像?

标签 ios 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)

关于ios - 如何快速使用滑动手势翻转 x 和 y 轴上的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43222239/

相关文章:

unit-testing - 在 Swift 中模拟

ios - 为获取请求设置谓词

objective-c - NSMutableArray indexOfObject 返回一个非常大的数字

swift - Swift 中的核心数据属性重置

ios - 如何在 Swift 中从 C 向数组追加新的 String 元素

swift - 使用多边形三角剖分创建自定义几何体并在 SceneKit 中应用纹理坐标

iphone - 通过 View Controller 切换时应用程序崩溃

ios - 具有弯曲边缘和透明状态栏的短 UINavigationBar

ios - 获取 UIWebview 的当前域

ios - 在 swift 3 中使用 PKHUD 创建自定义 View