Swift捏缩放图像质量

时间:2017-07-03 10:55:54

标签: ios swift uiview uiimage pinchzoom

我正在从文本字段创建图像,我想在用户捏/缩放时放大新创建的图像。我得到的问题是图像的质量变得像素化,我似乎无法想到修复。

func imageFromTextfield(text: UITextField) -> UIView {

    UIGraphicsBeginImageContextWithOptions(text.intrinsicContentSize, false, UIScreen.main.scale)
    text.drawHierarchy(in: text.bounds, afterScreenUpdates: true)
    if let image = UIGraphicsGetImageFromCurrentImageContext() {

        UIGraphicsEndImageContext()
        // Draggable view returns the pinch gesture
        let textImage: DraggableView = {
            let view = DraggableView(frame: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
            view.stickerImage.frame = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
            view.stickerImage.image = image
            view.contentMode = .scaleAspectFit
            view.clipsToBounds = false
            view.layer.masksToBounds = false
            view.translatesAutoresizingMaskIntoConstraints = false
            view.stickerImage.translatesAutoresizingMaskIntoConstraints = true
            return view
        }()
        return textImage
    }
    return UIView()

}

我已尝试增加字体大小并缩小框架但这不起作用。我该如何解决这个问题?

0 个答案:

没有答案