gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 12:26:34 24 4
gpt4 key购买 nike

任何人都可以帮助我,如何在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com