图片是有方向的!!

    ///根据图片的方向转换选择的区域
    ///
    /// - Parameters:
    ///   - rect: 要转的区域
    ///   - frame: 图片的frame
    ///   - orientation: 方向
    /// - Returns: return value description
    private func p_convertRect(_ rect:CGRect,onOriginFrame frame:CGRect,orientation:UIImageOrientation) -> CGRect {
        var x:CGFloat
        var y:CGFloat
        var width:CGFloat
        var height:CGFloat
        switch orientation {
        case .up:
            x = rect.origin.x
            y = rect.origin.y
            width = rect.width
            height = rect.height
        case .right:
            x = rect.origin.y
            y = frame.width - rect.maxX
            width = rect.height
            height = rect.width
        case .down:
            x = frame.width - rect.maxX
            y = frame.height - rect.maxY
            width = rect.width
            height = rect.height
        case .left:
            x = frame.height - rect.maxY
            y = rect.origin.x
            width = rect.height
            height = rect.width
        case .upMirrored:
            x = frame.width - rect.maxX
            y = rect.origin.y
            width = rect.width
            height = rect.height
        case .leftMirrored:
            x = rect.origin.y
            y = rect.origin.x
            width = rect.height
            height = rect.width
        case .downMirrored:
            x = rect.origin.x
            y = frame.height - rect.maxY
            width = rect.width
            height = rect.height
        case .rightMirrored:
            x = frame.height - rect.maxY
            y = frame.width - rect.maxX
            width = rect.height
            height = rect.width
        }
        return CGRect(x: x, y: y, width: width, height: height)
    }

你可能感兴趣的:(图片是有方向的!!)