I have been following Ray Wenderlics's tutorial on how to create a basic draw app.
Ive got it working perfectly except for when I draw the content mode changes on the uiimageview.
I've set it to aspectFill in storyboard and applied an image
I think the problem is in my touches ended method
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
}
it changes the content mode to what appears to be scaleToFill or Scale to fit?
Does anybody know how I change this?
regards
Thomas
Update
Thanks Matt for your direction
Ive added the following code
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()
I think I'm on the right track but the image is now resizing to aspect fit rather then aspect fill.