UIScrollView automatically scrolls to next subview horizontally then bounces somewhere else - ios

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];

Related

Ensure UITextField stays onscreen despite scrolling

How can I ensure that a UITextField stays on screen despite not currently viewing the bottom of a UITableView? Like when I scroll up, how can it stay on-screen rather than disappear at the bottom of the screen. I want it anchored to the bottom of the screen at all times.
Edit: It does not appear when I add it as a subview.
2ndEdit: Stop docking post please..
You can add it to view that contains tableView i.e tableView superView.if your viewController has tableView.You can do like
self.view.addSubView(yourTextFied)
self.view.bringSubviewToFront(yourTextFied)
and set the frame of yourTextField approprately

After scroll visible coordinates for the objects in the UIScrollView

I have a UIScrollView which contains 12 buttons. Only 5 buttons are visible at a time and rest all are not. When user clicks on a button i am animating a UIView from the position of the button. So when I scroll for hidden buttons and click view animation start from bottom from its original coordinates but not from the visible coordinates of the button.
When user scroll i want to know the visible coordinates of the button (contained in uiscrollview), so that I can animate from the button visible position. Or can anybody suggest which is the best way to implement this animation.
Note: My Scrollview is part of viewcontroller. I can't customize the scrollview as a parent class. Please help me asap to solve it as i am at the end of application development.
I just solved it using Scrollview convertPoint:toView API. Here is the solution:
CGPoint aPtInScrollView = [viewA convertPoint:aPoint toView:self.view];
Where aPoint is the object in scrollview 'position

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.

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;

horizontal scrolling of a scrollView in a scrollView - small problem

i have a scrollView that fits the whole screen. In that View i show some UIImages that scroll horizontally. Like in the PageControl Project from Apple.
Then, when the user taps the screen, i fade in a scrollView at the bottom with some other images. Also horizontally scrolling. Like in the ScrollView Project from Apple.
My problem is, that when i come to the end of the scrollView which was faded in, the upper scrollView also starts to drag. How can i stop that during activation of the second scrollView?
Redraw the frame limits on your first scrollView when the second enters the screen. That way, your touches won't respond to both views. This means you need a container-view to keep both views seperated from each other.
Then you just rescale it back whenever your second scrollView disappears.
Edit: or disable scroll in your first scrollview while the second is open.

Resources