美文网首页
图片是有方向的!!

图片是有方向的!!

作者: 轻云绿原 | 来源:发表于2017-08-26 16:14 被阅读9次
        ///根据图片的方向转换选择的区域
        ///
        /// - 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)
        }
    

    相关文章

      网友评论

          本文标题:图片是有方向的!!

          本文链接:https://www.haomeiwen.com/subject/cntvdxtx.html