UIImageView inside UIScrollView bleeding over next page - uiscrollview

I have a UIScrollView and a UIPageControl with 5 pages. Each page is set at a different background color. Each page is 1024 x 768 and only landscape mode is supported and the content size is set to: scrollView.contentSize = CGSizeMake(1024 * 5, 768);
Each page shows the right background color with the right size.
I place a UIImageView on each page which I can move around. From page 2 onward (or index 1), if the image is moved to the left age and onward it bleeds over to the previous page, you can actually go to the previous page and see part of the image there.
The same however does not happen for the right edge. If the image is moved past the viewable area, you don't see the image on the next page.
My question is how is this possible and what can I do to prevent it?
Thank you in advance

After much playing with this, to help others that may run into the same situation, the answer to this problem is to set:
self.view.clipsToBounds = TRUE;
on the view where your UIImageView(s) are added as a subview. For me, each page was an instantiation of a UIViewController class with the view set to the bounds of the window.

Related

UIScrollView contentLayoutGuide and zooming centered

The problem to be solved here is how to zoom in a UIScrollView while staying centered. If you don't take some sort of precautions, the default is that as we zoom out, the zoomed view slides up to the top left corner of the scroll view, like this:
So how to prevent this, and keep the zoomed view in the center as we zoom? As you probably know, there are traditional ways of handling this by messing with the scroll view's layout, as described by Josh and Eliza in the brilliant classic WWDC video 104 from 2010. This can be done by using a delegate or by subclassing UIScrollView, and gives the desired result:
Now comes WWDC 2017 video 201 (https://developer.apple.com/videos/play/wwdc2017/201/?time=1496), and there's Eliza making a claim that the new (iOS 11) contentLayoutGuide solves the problem of zooming while staying centered in a new way: she says to center the content view at the center of the content layout guide.
But she doesn't demonstrate. And when I try it for myself, I find it isn't solving the problem. I'm zooming in just fine, but when zooming out, so that the zoom scale is smaller than 1, the content view moves up to the top left, just as it always has.
Has anyone figured out what this claim in the video actually means? How does iOS 11 make it easier to zoom centered than in the past?
EDIT I actually received a sample project from Apple in response to my bug report, which they claimed illustrated how to solve this, and it didn't! So I conclude that even Apple doesn't know what they're talking about here.
The view goes to the top left because the contentSize of the scroll view is not defined. When using the new Auto Layout guides in iOS 11, it's still necessary to define the contentSize.
Add the following constraints:
scrollView.contentLayoutGuide.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor),
scrollView.contentLayoutGuide.heightAnchor.constraint(equalTo: scrollView.frameLayoutGuide.heightAnchor)
This worked for me, when I had a contentView with a fixed width/height and the following additional constraints:
// give the centerView explicit height and width constraints
centerView.widthAnchor.constraint(equalToConstant: 500),
centerView.heightAnchor.constraint(equalToConstant: 500),
// pin the center of the centerView to the center of the scrollView's contentLayoutGuide
centerView.centerXAnchor.constraint(equalTo: scrollView.contentLayoutGuide.centerXAnchor),
centerView.centerYAnchor.constraint(equalTo: scrollView.contentLayoutGuide.centerYAnchor)
This is the solution you are / everybody is looking for. In my case I want to center a view inside a table view scroll view. So if the table view scrolls the custom view will always be in the center of the scroll view content.
// create a view
let v:UIView = UIView(frame:CGRect.zero) // use zero if using constraints
ibTableView.addSubview(v)
ibTableView.bringSubview(toFront:v)
v.translatesAutoresizingMaskIntoConstraints = no
v.backgroundColor = .yellow
v.widthAnchor.constraint(equalToConstant:100).isActive = yes
v.heightAnchor.constraint(equalToConstant:100).isActive = yes
// set scrollview guides
ibTableView.contentLayoutGuide.widthAnchor.constraint(equalTo:ibTableView.frameLayoutGuide.widthAnchor).isActive = yes
ibTableView.contentLayoutGuide.heightAnchor.constraint(equalTo:ibTableView.frameLayoutGuide.heightAnchor).isActive = yes
// anchor view
v.centerXAnchor.constraint(equalTo:ibTableView.contentLayoutGuide.centerXAnchor).isActive = yes
v.centerYAnchor.constraint(equalTo:ibTableView.contentLayoutGuide.centerYAnchor).isActive = yes

UIBarButton image drifts into position on when view is rendered

I have several icons on my toolbar. One of which (highlighted in red) seem to 'drift' into position when view is rendered as if the flexible space kicks in after the image is rendered. Also, the image kind of moves from the adjacent button's top left corner (the filter icon) into position.
This only happens if the app is launched when an update became available while the app was either terminated or was in the background. While I do not understand why, it seems that rendering the default icon in viewDidLoad, followed by server status check and a change of image is the sequence that causes the issue.
Any thought what might cause this behaviour will be appreciated!
Code is very simple:
if newDataAvailbleOnServer() {
myBarButton.image = cloudWithArrowImage
} else {
myBarButton.image = simpleCloudImage
}
both images are of the same size and density.

How to get background images to scale to the same size in Xcode Autolayout?

The Problem:
I am currently trying to get the background image of launch page of my app and the first view controller to match in size.
On left, launch screen on the right first view controller.
However as you can see the navigation bar appears to resize the background image.
Both back ground images are currently set to centre vertically and horizontally and both have equal width and height to the view.
What Ive tried
I have obviously tried messing around with auto layout to now avail,
I have also tried toggling the Extend Edges “under Top Bars” option, it is currently set to true in the above image. This didn't work either.
Question
How do I get both background images to have the same sizes (consistent) between the launch screen and the first view controller, for all iPhone devices (in auto layout)?
Found the answer for anyone with this problem.
Tick extend edges under Opaque bars for the view controller.

ImpressPages 4: Not all pages have the same width

There is a strange behaviour in one of my installations with ImpressPages: Not all pages have the same width.
I'm using the default theme "Air".
The installation is at
http://www.impresspages.ch
It is the page "Link" that has not the same width as the other pages.
Any idea what causes this?
Your website looks normal. Maybe you see that center content goes slightly to the left on that page? If that's the case, it means that on your screen that page gets a visible scrollbar. And the browser you use hides/shows the scrollbar only when it's needed. For that reason the area for the page shrinks and automated centering ends up on a different position.

Center image horizontally & vertically on page with % margins and be resizable with window

It seemed so simple just a day ago, but I can't figure it out:
How do I center an image on a page, giving it fixed % margins (10% on all sides) and still have it scale with the window on resize?
It's very important that the page and the image display well on all platforms, without scrollers (!).
The page itself is very simple and only contains the image (which on different versions of the page has different dimensions), and a bar on the top with a link to send it to another page.
The max size of the image would be 1500x1000px, no minimum size.
I wholeheartedly hope someone can help me out with this, thanks so much!
Best way to do that is using JavaScript. Get the window size, subscribe for window.onresize event and update the image size and position accordingly.
Using CSS only will NOT work, because any position properties depend on the container. In your case the container is the window, which will size itself based on the content. This creates a sort of circular dependency (window size depends on the image, the image size and position depend on the window size).
For information about getting the exact available window size in cross-browser way you could check this post: Get the size of the screen, current web page and browser window - haven't done that in a while to provide you with exact code.
Also note that you don't mention keeping the aspect ratio of the image. If it should not be maintained there is no way to do it HTML/CSS only, because all operations with them do maintain AR of images.

Resources