MY app is for iPad using Storyboards with two scenes. On one scene, I have a UIScrollView that contains a UIVIew. It scrolls, but bounces back immediately, rendering itself useless. The size of the UIScrollView is 768x590; the size of the UIView is 768x1590; ContentSize of the UIScrollView is 768x590. This is an image of the UIScrollView settings:
(I have looked at SO and Google for the past 6 hours, tried a lot of stuff, but nothing works. I have also done a CMD + Option + K (Clean) several times, and that didn't help either.
Why does it not scroll properly?
Found what works for me!
When you embed a view into a UIScrollView in InterfaceBuilder, then
there's a constraint automatically set. If your view is "longer" than
the screen in portrait, it wont scroll at all.
But if you rotate the screen, you'll notice the ability to scroll a
little.
To get UIScrollView going in AutoLayout look into your constraints.
Find "Vertical Space - Scroll View - View" and set it from "constant"
to "auto" - fixed everything for me.
Thanks for your help... I appreciate it.
Your scrollView height is less than the uiview which is the subview in your case of scrollview and for scrolling it fully you will have to set your scrollview contentSize height more than the height of the view you are scrolling in it,please give a check on this point.
Related
I have a followed this answer Putting a UIScrollview in a viewcontroller (storyboard) to embed a scrollview in a viewcontroller (Mine is vertically instead of horizontally).
All the constrains are working except the fact that the view bounces back when it is let go. I have tried a lot of different solution, but none is working! Please help, I'm using autolayouts my main goal is to be able to show all the buttons on the screen through scrolling.
EDIT:
I have been trying all types of ways to increase the contentSize, but nothing happens - the scrollview won't scroll properly. I tried different codes from people with the same problem, but the bouncing won't stop. Am I doing anything wrong on my constraints? This is extremely frustrating, please help. My constraints (using autolayout) (as I said, I followed this answer Putting a UIScrollview in a viewcontroller (storyboard))
You have to increase your scrollView's contentSize to fit all of it's sub views.
You should add subview to scrollview, then add all other views to that subview.
scrollView
contentView
subview_1
subview_2
Then add constraints between scrollView and contentView (leading, trailing, top, bottom) and contentView should have width and height constraints set properly (set width equal to scrollView width)... the content size will be calculated automatically.... just set height
I am facing a very strange problem. Trying to implement constraints to my view controller makes my button inactive.
My view hierarchy is
UIVIew
UISCrollView
UIView
UIView
UIButton
There are many other views but just for simplicity. One thing is that there is an UIImageView object, which I am stretching to the view according to size but not objects are overlapping or similar, but might be related.
Basically all the constraints are in storyboard. Only for the image view I am using manual setting.
self.imageViewHeight.constant=imgHeight;
when I disable auto layout the button works just fine.
EDIT: Latest observation :Just found out that simulator iPhone 6+ works fine with the constraints. The same is happening with a similar view, which is smaller so all iPhone works just 4S.
So it is definitely issue related to screen size and manipulating with constraints.
Looks like all objects that are bellow screen view itself after creation, so you have to scroll it to see them are inactive.
Any help will be greatly appreciated.
It seems you need to increase the frame Width or Height (whatever you need) of container view. The contentSize of scrollView only affects how it will scroll, which is irrelevant here.
If the button is outside the container view, it will still show up. However, it can't respond to any touch event.
HERE WHAT WE NEED TO DO FOR TOUCH RESPONSE
All you need to do is set bunch of constraints for CONTAINER VIEW of scrollview. Start from adding leading, trailing, bottom, top, width equal and height equal. Now in my case, I need fixed contentSize of Scrollview, so i change priority of equal width constraints to 750. For dynamic contentSize, you need to set priority programmatically.
Comment below if you have any query..
Thanks
I am having a very frustrating issue. I know there are all kinds of issues with UIScrollView in iOS7 and XCode 5. I need to implement a scrollview and there are all kinds of tutorials showing you how to do it by switching off auto layout but that then messes with the rest of the views in my app.
I tried the fix of putting my subviews into a container UIView and placing that in the UIScrollView and setting the scrollview's content size to the size of the contained UIVIew. That didn't work. Now I am working with placing everything in the scrollview and it all works with one exception. When I load the view on the simulator or a device the content view is moved down but somewhere around 60 points or so. See image below.
That white space below the title bar on the right is still the scroll view as I can press and drag within it. Adjusting the contentOffset doesn't do any good as that just scrolls the view down slightly. I have no idea what to do here.
Just a little more info: I setup the scrollview and all the subviews in storyboard and the connected them up. Not sure if that has any bearing on it.
Thanks in advance for any help you can provide.
I think your Scrollview top space constraint have 64 pixels. That's a problem. So, set your top space constraint value to 0.
You need to add the constraints before view displayed then contentsize will be set automatically.
Check UIScrollView's autoresizing mask. It has to be set like this.
This is a storyboard app. I added a UIScrollView on top of the UIView that is there in the view controller by default. Then I added some UI elements on to the scroll view. After designing the viewable part of the Scroll view, using its handles I stretched it vertically and pushed it up a bit so that that part is visible for me to design the rest of the screen. After I was done I positioned the scroll view back to fit the view. Please note that I did not resize the scroll view to match the size of the view from the IB.
Then I added all 4 constraints to the scroll view (Leading and Trailing space to superview, Top and Bottom space to superview). Then I selected the UIView, opened up the size inspector and changed the Bottom Space to superview's value to 0. That automatically resized the UIScrollView to fit inside the view controller.
Then I added the following lines of code inside the viewDidLoad method.
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.scrollView.frame.size.height);
self.scrollView.frame = self.view.frame;
But this does not work. The UIScrollView won't scroll. Yes, the scrolling is enabled.
Can anyone please tell me what I might be missing here?
Thank you.
EDIT:
I found an old project of mine here. It utilize the way I just explained above and it works! No idea why it doesn't anymore.
I also added a demo project here with the issue.
If I understood your code correctly (a screenshot of the view would help) you set the scrollviews frame to be full size of the view and set then contentSize to the view's size. A scrollview scrolls only if the contentSize is larger than its size.
This might not be the complete answer to your question, but it will help you and others for sure.
To design the views that are bigger in size than the size of the UIScrollView, the best way to have the UIView as a child view to UIScrollView and put all the content on the UIView and finally place the UIView as subview of the UISCrollView. AT last you can set the size of the UIView as the content size of the UISCrollView.
Cheers. :)
In my UIViewController I have a UIScrollView and UIView. These are two different view, means UIView is not inside UIScrollView. I have different view on scrollview that i am setting programmatically and increasing contentSize. And this UIView is hidden, i am showing is sometimes. The problem is that when i hide this UIView, that UIScrollView stops scrolling.
Why this happening?
I have set all leading edges to superview of both. Does it matter?
Please guide me.
Hi all, I am sharing the image of my ViewController Scene
I am using auto layout (iOS6). Scroll View ContentSize is (768,1400) which i am setting in ViewDidAppear. The View below Scroll View is hidden and Scroll View is scrolling without any problem.
Now if i show and hide the View, the Scroll View locks, its not scrollable now.
That is problem i am facing.
I am not doing anything in code more than setting content size.
If you need any other information, please tell me.
The contentSize in iOS 6 "auto-sizes" itself with auto layout. This means you cannot set the contentSize. There are hacks that suggest setting it in the viewDidAppear call, but I would avoid this. If you read the iOS 6 release notes (search for UIScrollView on the page) it gives you a couple solutions. One of them involve the translatesAutoresizingMaskIntoConstraints property.
Remove all your code related to sizing the scrollview content size. Autolayout uses this while you are scrolling now. After you do this add the following code
// Add 200 points to the bottom of the scroll view
[self.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 200, 0)];
self.scrollView.translatesAutoresizingMaskIntoConstraints= NO;
Without any code, I'll hazard a guess...
This would be typical in a case if your contentSize doesn't exceed the size of your UIScrollView. If you were to, say, hide your view, then change the size of your scroll view and your scroll view exceeds or is equal to your contentSize, then you will not have anything to scroll.
Another possibility is if you have disabled user interaction.