Reputation: 331
I have an application where by I take a picture and then go on to present this image in a different UIViewController. However, the resulting UIImage appears to expand beyond the bounds at which I set the UIImageView. The content mode is 'Aspect fill'
After taking the picture, the following method is called: CaptureImageViewController:
func presentCapturedImage(image: CGImage, observationObj: VNRectangleObservation) -> Void {
print("HERE!")
let prevVC = storyboard?.instantiateViewController(withIdentifier: "prevcrop") as! PreviewCropViewController
prevVC.cgImg = image
prevVC.uiImageEXIF = uiImageEXIF
prevVC.ObserObj = observationObj
DispatchQueue.main.async {
self.present(prevVC, animated: true, completion: nil)
}
}
PresentingViewController calls the following in its viewDidLoad():
@IBOutlet weak var imgPreViewOutlet: UIImageView!
guard
let img = self.cgImg,
let imgEXIF = self.uiImageEXIF else{return}
let uiImage = UIImage.init(cgImage: img)
self.imgPreViewOutlet.image = uiImage
The UIViewController that I use to present the image:
The Constraints of the lower UIView holding the UIButton:
The constraints of the UIImageView:
The resulting view - you can see the image covers almostall of the crop button:
Upvotes: 1
Views: 1621
Reputation: 1061
Beware when using aspectFill
in UIImageViews. If clipsToBounds
is not true, the image will probably extend outside the frame.
This happens as the image is scaled in such a way to fully fill the image view frame. If the proportions of the image and frame aren't exactly identical, the image will extend outside the frame.
Upvotes: 9