ScrollView changes suddenly its position - ios

I've a very strange problem with my scrollView.
First of all, this is my scrollView:
...and in my viewDidLoad:
_scrollView.contentSize = CGSizeMake(320,500);
The scrollView seems to work when I start the app. But when I scroll down to the bottom of the scrollView and click another tab in the tabBar while the scrollView is still at the bottom, and then go back to the tab (ViewController) with the scrollView, there is free space at the bottom added (which wasn't there before), but in return the top of the scrollView cuts off my content which is positioned at the top. >>> The space which appears on the botton is left on the top of the scrollView
This only happens, when you go to another tap while staying at the bottom of the scrollView.
I know this is very difficult to explain, but I hope you understand my problem and can help me.
I set the content the following way:
-viewController
-View
-Scroll View
-buttons, images, etc.
-tabBar item
-navigationItem

I've found a solution now:
-(void)viewWillAppear:(BOOL)animated{
[self.scrollView setContentOffset:CGPointZero animated:NO];
}
...I now this solution is not 100% good, but for my problem its ok :)

Related

Scroll bar scrolls but UIScrollView doesn't scroll

I have components in a UIScrollView. My scroll view works when it was in iOS 10 and Xcode 8 but after the update, my scroll view does not scroll. However, the scroll bar does scroll and can keep scrolling until it gets smaller and smaller. It is just the elements in the scroll view itself that doesn't scroll.
I have tried doing content size bigger than the frame size but it does not fix it. Here is my current views hierarchy.
If anyone can help me debug this, it would be greatly appreciated.
I fixed this by adding a content view to the scroll view, and then the scroll view should be the subview of main view. The hierarchy should look like this.
I encountered pretty much the same problem (scroll indicator moves and gets smaller but content doesn't move). In my case it was resolved by changing the AutoLayout constraint for the top of my content view within the UIScrollView. I had pinned it to the Frame Layout Guide rather than the top of the superview.

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.

Horizontal ScrollView inside Vertical ScrollView

I have a UIScrollView that scrolls vertically. Inside of that, I have a UIScrollView that scrolls horizontally. I will call them verticalScrollView and horizontalScrollView.
My first problem was that verticalScrollView would scroll up and down, but the horizontalScrollView would not scroll at all. After turning off Autolayout and setting the content sizes in viewDidLoad, the verticalScrollView would always immediately scroll down the bottom upon appearing on screen and only be able to scroll up a little, but the horizontalScrollView (which is at the bottom) scrolls left and right perfectly.
I have tried almost everything that I have found online, but nothing seems to allow me to scroll vertically with the Main ScrollView (verticalScrollView) and scroll horizontally with the child horizontalScrollView.
I can post any more information that may be helpful. Thank you.
UPDATE (8-15-13): I put the hortizontalScrollView into a UIView, and put that UIView into the verticalScrollView. I am now able to scroll freely in the verticalScrollView, but can only scroll one swipe left or right in the horizontalScrollView before it snapping back.
In ViewController.m, I set the content sizes.
[_verticalScrollView setContentSize:CGSizeMake(320, 1905)];
[_horizontalScrollView setContentSize:CGSizeMake(960, 190)];
Please check your Autosizing is top-left or not? May be something wrong in size inspector view in XIB.
Hope this can be helpful to you.

Reset Scroll View when returning from View Controller

UIScrolView Noob Here..
I currently have two view controllers.
First view controller contains a Long Image View embedded in a UI View embedded in a scroll View.
Image view has a button at the top and at the bottom. Both buttons lead to the next view.
Scroll is working as i can scroll to the bottom of the image and back to the top.
when top button is clicked i am taken to next view...then a button from there can return to the first view and i can continue scrolling down and back up.
Problem occurs when bottom button is clicked and i then return from the next view.
I cannot scroll back upwards and can only see the bottom part of the image.
by looking online ive found two potential solutions, of which neither work for me:
sol1:
[self.scrollViewFront scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
sol2:
[scrollViewFront setContentOffset:CGPointMake(0,0) animated:YES];
my scroll view contentSize is set as follows:
self.scrollViewFront.contentSize = CGSizeMake(320, 775);
There must be a way i can return back to the top half of the image instead of being stuck towards the bottom.
Thanks for any help.
I suspect your issue is not with the scrollView, but with the transition to or from the second next view. Try swapping the actions associated with the buttons. Does transitioning to the view originally associated with the top button work if associated with the bottom instead?

Multiple vertically scrolling UIScrollViews in a horizontal UIScrollView

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.

Resources