UIImageView resize issue in UIPageViewController

I am creating a new application and want to start the "welcome walkthrough" at the beginning when I have a storyboard with a series of images presented in the UIPageViewController. I upload images and all this is fine, but the images change every time they go beyond the "previous" or "next" ViewController. I use Swift for development.

Here is the problem video: http://youtu.be/dXcjjT-8Bk0

I tried all the different view modes (Aspect fit, aspect fill, redraw, etc.) and they all behave the same.

I use Auto-Layout + Size classes, because I want to simplify development for different screen sizes. The current restrictions that I have make UIImage visible in the correct size:

 Align Centre X to Superview Top Space to Top Layout Guide Bottom Space to Bottom Layout Guide + Equals: 50 

I am currently using Aspect Fit , which gives me the correct image (after they have completed their "resize".

Can someone explain to me how to fix this?

+15
ios swift uiimageview uipageviewcontroller
Jan 06 '15 at 7:14
source share
3 answers

From your video, I noticed that your UIImageView always “modified” at the top, not at the bottom. This is certainly related to your autodetection restriction, which you call the "Top Space to Top Layout Guide". As long as your UIImageView view UIImageView goes through your scroll view controller, it doesn't know where the top layout is, so its topLayoutGuide.length is 0 . Only after the animation is complete, the view controller receives a positive value for topLayoutGuide.length . Yes, the pageview controller should be a little smarter than that, but it is not. You can either stop using the top layout guide, or restrict autodetection to the top of your supervisor. Or you can continue to use the top layout, but consider when its length is 0 . You can do this by creating an output for your NSLayoutConstraint storyboard and overriding viewWillLayoutSubviews() in the ViewController containing your UIImageView s:

 @IBOutlet weak var topSpaceToTLG: NSLayoutConstraint! var parentTLGlength: CGFloat = 20 override func viewWillLayoutSubviews() { if self.topLayoutGuide.length == 0 { // Lengthen the autolayout constraint to where we know the // top layout guide will be when the transition completes topSpaceToTLG.constant = parentTLGlength } else { topSpaceToTLG.constant = 0 } } 

This will always put the top of your UIImageView in the top layout guide, assuming the status bar is always 20 points. Before laying out the subheadings, he checks whether the length of the top layout is 0 or not, and adjusts the auto-detection limit accordingly. After the transition animation is completed, the layout starts again, and the upper length of the layout guide is expected, so the constraint constant may return to 0 . Even better than hardcoding, the value is to convey in the parent view the exact length of the controller during initialization, given any possible changes to the start guide, such as adding a navigation bar.

+14
Jan 13 '15 at 6:10
source share

From a video that I think you could solve this by preventing the UIPageViewController from expanding under the upper bars.

In xcode, you can do this using the attribute inspector for the page view controller by unchecking the "Extend edges in upper bars" checkbox.

This should prevent it from swapping in the status bar, I think, helping to avoid the switch that you see.

+1
Jan 14 '15 at 11:34
source share

I realized that the problem was that when the view manager started animating the top and bottom layouts, the guides did not have height. The right and left fields were not there either. When the view finished the animation, they all got height or width, and my view resized. I fixed this problem in my project by adding vertical restrictions between my objects and their super-representation, and not in the Top / Bottom Layout Guide. I also had to change my horizontal limits to ignore side margins.

The last problem I ran into was that I myself had to go into the status bar. It may or may not be, or it may be a double bar, for example, when you use Maps.

+1
Aug 26 '15 at 21:15
source share



All Articles