【发布时间】:2017-04-13 17:06:08
【问题描述】:
我一直在关注 Ray Wenderlics 关于如何创建基本绘图应用程序的教程。
除了我在 uiimageview 上绘制内容模式更改时,它工作得很好。
我已在情节提要中将其设置为 aspectFill 并应用了图像
我认为问题出在我的触摸结束方法上
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if !swiped {
// draw a single point
drawLineFrom(fromPoint: lastPoint, toPoint: lastPoint)
}
// Merge tempImageView into mainImageView
UIGraphicsBeginImageContext(mainImageView.frame.size)
mainImageView.image?.draw(in: CGRect(x: 0, y: 0, width: mainImageView.frame.size.width, height: mainImageView.frame.size.height), blendMode: CGBlendMode.normal, alpha: 1.0)
tempImageView.image?.draw(in: CGRect(x: 0, y: 0, width: mainImageView.frame.size.width, height: mainImageView.frame.size.height), blendMode: CGBlendMode.normal, alpha: opacity)
mainImageView.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
tempImageView.image = nil
}
它将内容模式更改为似乎是 scaleToFill 或 Scale to fit?
有人知道我是怎么改的吗?
问候
托马斯
更新
感谢马特的指导
我添加了以下代码
let imageSize = AVMakeRect(aspectRatio: (mainImageView.image?.size)!, insideRect: mainImageView.frame)
mainImageView.image?.draw(in: CGRect(x: 0, y: 0, width: imageSize.width , height: imageSize.height), blendMode: CGBlendMode.normal, alpha: 1.0)
tempImageView.image?.draw(in: CGRect(x: 0, y: 0, width: imageSize.width, height: imageSize.height), blendMode: CGBlendMode.normal, alpha: opacity)
mainImageView.image = UIGraphicsGetImageFromCurrentImageContext()
我认为我在正确的轨道上,但图像现在正在调整大小以适应方面而不是方面填充。
【问题讨论】:
-
有什么更新吗?你能解决这个问题吗?
标签: swift uiimageview core-graphics