Posts

Post not yet marked as solved
8 Replies
I have created now simple test project with Xcode 10.3 on iOS12 and tried with Simulator.I have added ImageView on the Main storyboard and set constraints to the Safe Area (Leading, Trailing, Top, Bottom).And this is the whole codeclass ViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let newBackFrame = CGRect(x: 20, y: 20, width: 100, height: 150) self.imageView.frame = newBackFrame }And it works, the ImageView is resized when shown.I tried the same with Xcode 11 beta, iOS13 with Simulator and it does NOT work, the ImageView is not resized.That proves my first thesis.Could you please try the same?It seems that it works with viewDidLayoutSubviews() as you suggested 🙂Tho problem is with my View that ImageView has parent UIView and the constraints to it (same width/height, centering).When I did the same in the sample project, it does not work.I am trying to find a solution.If you have an idea how to overcome this, that would be great.Maybe if you have some knowledge about what was changed in this part with iOS13.Anyway thanks a lot for your support
Post not yet marked as solved
8 Replies
I change the size just in viewDidAppear.Yes, there were constraints on the imageView and probably this is the reason, as you said, why it is not working.But, what confuses me is that the same code works OK with iOS 12.btw. I tried this change also with viewDidLayoutSubviews(), but again no luck.I guess I will have to tackle and change the constraints.
Post not yet marked as solved
8 Replies
Yes, only in viewDidAppear.If I remember correctly, I had to put it there, because at that time the image is drawn with the correct frame according to the AspectFit- mode.And then immediately I want to shring the parent ImageView to the same frame.I tried with setNeedsDisplay(), but unfortunately no change.The frame- variable was declared outside, therefore unwrapping. var newBackgroundImageViewFrame:CGRect? = nil if newBackgroundImageViewFrame == nil { let imageSize = self.backgroundImage?.size...// newBackgroundImageViewFrame = CGRect(x: hOffset, y: vOffset, width: realImageWidth, height: realImageHeight) newBackgroundImageViewFrame = CGRect(x: 20, y: 20, width: 100, height: 150) }But you are right, I can simplify it, at least for testing.
Post not yet marked as solved
8 Replies
Here is a part of a codeI call it in the viewDidAppear. override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) resizeView() private func resizeView() { // calculate the new frame for the background image view for border around the image newBackgroundImageViewFrame = CGRect(x: 20, y: 20, width: 100, height: 150) } self.backgroundImageView.frame = newBackgroundImageViewFrame!I check, the method is executed.First the image itself need to adapt itself inside of the ImageView (using AspectFit- mode)Then the ImageView needs to shrink the frame to be the same as the Image- frame.It works with iOS12, but not in 13.1