Multiple vertically scrolling UIScrollViews in a horizontal UIScrollView - ios

I'm developing an app, where I have one horizontally scrollable UIScrollView fullscreen with pagination that contains multiple (let's say 3) vertically scrollable UIScrollViews, each also fullscreen. They're positioned without margins, the left ones origin is (0,0).
Each vertically scrollable UIScrollView consists of buttons placed one above the other, each when clicked, presents a ViewController:
[self presentViewController:someViewController animated:YES completion:nil];
Now this code works fine for the two right UIScrollViews, but it's buggy for the left one:
The buttons bellow the height of the horizontal UIScrollView are not clickable. So if the height of the horizontal UIScrollView is 440px, any UIButton with origin.y > 440 is uncklickable.
If the UIScrollView is slightly scrolled down and a button is clicked (that is not below 440px), the whole UIScrollView gets "moved" down and gets sorta laggy while the requested view controller gets presented. When this view controller gets dismissed, the scroll view stays lower. If I scroll it back up and press a button, it magically jumps up to where it should be.
Now for the fun part!
If I change the origin of the left UIScrollView to (1,0), this issue dissapears! What could be making this problem?
Some added code:
[horizontalSV setDelegate:self];
[horizontalSV setContentSize:horizontalContentView.frame.size];
[horizontalSV addSubview:horizontalContentView]; // View containing vertical scroll views, it's set up in IB
[horizontalContentView setFrame:CGRectMake(-1, 0, 961, 440)]; // This is now used for the hack
// Now imagine three of these
firstSVcontent = [[VerticalContentView alloc] init]; // Setting the content view
[firstSVcontent setTitle:title];
[firstSVcontent setButtons:blahblah];
[firstVerticalSV setContentSize:firstSVcontent.view.frame.size]; // Setting vertical scroll view
[firstVerticalSV addSubview:firstSVcontent.view];

I've resolved this issue almost a year later!
The problem was, I was doing most of my view managment in a XIB file and then I just read those content views and scroll views in my viewDidLoad method and put them together.
Now I've rewritten my code to create all scroll views and content views programatically and everything works without a problem.

Related

Putting a UIScrollView inside a UIPageView, scrolling doesn't work

I'm making a pageview that has a bunch of scrollable pages inside it. I have the pageview working, and the viewcontrollers that it rotates each have a scroll view inside them. The problem is, I think, that the scrolling doesn't happen because the touches don't get through to the pageview. The scroll view should only scroll vertically, while the pageview works with the horizontal scrolling. Is it possible to send through only the vertical touches, or is there another way?
Thanks
If you're using a storyboard, open the Attributes inspector of the embedded UIScrollView and deselect the "Shows Horizontal Indicator" option. Do the same on the UIPageViewController, but for the "Shows Vertical Indicator". However, you also have to ensure that the scroll view's contents aren't wider than the scroll view itself; to do this, just constrain the contents' width to be equal to the scroll view's parent.

UIScrollView automatically scrolls to next subview horizontally then bounces somewhere else

UIScrollView has several UILabel subviews, which are set to scroll horizontally (think about Instagram filters scrolling view). I can scroll UIScrollSubview, act upon tapping on a UILabel subview. Next thing I would like to achieve is to programmatically scroll to an invisible UILabel subview, when the users selects the last visible subview on the right (similar to how the instagram filters scroll out of the visible area when the user selects the last visible filter).
When the user touches the last visible UILabel subview, I execute
[_scrollView setContentOffset:CGPointMake(64, 0) animated:YES];
where 64 is the width of every UILabel subview of the scrollView.
This works fine only on the first selection event of the last visible subview. Once the scrollView scrolled to reveal the desired subview on the right side of the selected one, and I select newly revealed subview, the scrollView correctly scrolls to the left revealing the next invisible subview, but then jumps back (to the right) two positions (128). The desired behaviour is to always scroll to the left when the last visible subview on the right is selected (right now this happens only on the first selection).
Any suggestions would be appreciated.
Thanks.
EDIT: The bouncing issue went away in 2 cases:
scrollView.pagingEnabled: NO;
user performs relatively long touches on subviews
You should add 64 to the current contentOffset.
[_scrollView setContentOffset:CGPointMake(_scrollView.contentOffset.x + 64, 0) animated:YES];

iOS 7.1 Why is my UIScrollView scrolling away on showing keyboard?

I have a UIScrollView designed with IB.
UIView
UIScrollView
UIView
UITextField
UIButton
...
If I tap on the text field the view scrolls away towards the upper left corner of the screen before the keyboard is appearing. The space above the keyboards remains empty. I can scroll back the view if I drag in this empty space.
I have googled around, but found only postings where users want to scroll UIScrollView. I want the view to stay where it is.
Thanks in advance for any suggestions.
Here's what happened.
You designed the whole thing in Interface Builder.
The scroll view was not scrolling, so you set its contentSize in code to the size of the scroll view's primary subview (what I like to call the content view).
The scroll view was still not scrolling, so you munged the content insets - and this caused the problem that brought you here.
Your mistake was (3). Instead, you should have thought more about (2), i.e., why isn't my scroll view scrolling even though I have given it a nice big content size?
The answer is that, in a storyboard or xib that has auto layout turned on, that's not what you do. What you do is use constraints from the content view to its superview (the scroll view), on all four sides. Set the constant for all four constraints to zero. This causes the content size to match the size of the content view, automatically.

UIScrollview, other controls, not scrolling

I have an app which shows two images housed within a UIScrollview.
The scrollview is of size (320, 530), underneath it is an imageview size (320,38), this acts like a dock at the bottom of this screen, ( in fact it has to be there at the bottom of all screens in this app).
As it stand the scrollview works fine and the images switch from one to anothr when the user
moves the scrollview.
The problem is, I need the scrollview height to go all the way down ( from 530 to 568), and end up behind the dock imageview, when I change its height and the height of images within it, it just stops scrolling.
Is this impossible in scrollviews? does it have to have all of its screen real estate as top view?
Any solutions for this?
Thanks.
Update :
so I worked on the alpha and the image constraints, and the bottom imnage is located properly,
still the scrolling is not functioning.this is the latest code with changes.
http://ge.tt/4LYJGWl/v/0?c
thanks.
This is certainly possible. Add a full height scroll view to the controller's view, then add the small image view to the bottom. In the scene list at the left move that image view up so it's directly underneath the main view, which will make it a subview of that view rather than the scroll view (you'll then need to move the scroll view up above the image view so the image view will appear on top). You'll probably have to change some constraints to pin it to the bottom, and give it an alpha value less than 1 so the scroll view will show through.
After Edit
This is the screen shot of the scene from your updated code:
You only have one view that's directly under the main view, your scroll view. Compare that to my image.

How do I prevent a scroll view from letting a user (temporarily) scroll a UIScrollView out of it's content area?

UIScroll view lets me declared a scrollable area when I have too much content for one page. Strangely, the scroll view in question behaves as desired in the X-axis, with no scrolling whatsoever allowed. Unfortunately, the Y axis -- where scrolling is necessary -- doesn't 'clip' the allowed scroll area to the content size. The user can scroll outside of the content size, and only after they let go does scroll view 'bounce' back to the allowed zone.
I want to prevent the user from scrolling further up than there is content to view (down doesn't bother me) because it looks 'wrong' to have the header at the top of the scroll view pull down, leaving the regular background behind it.
If you are making your UIScrollView in interface this is as simple as deselecting the
"Bounces, Bounces Horizontally, and Bounces Vertically"
check boxes in your scrollView's attributes. If you are designing the UIScrollView in code you can add this.
self.textView.alwaysBounceHorizontal = NO;
self.textView.alwaysBounceVertical = NO;
self.textView.bounces = NO;

Resources