Preventing ScrollView from scrolling in certain area? - iphone

I hope you can help me...
I have a scrollview (UIScrollview) that contains a contentView (UiView).
Inside the contentview I have a Horizontal slider. My problem is that if the user swipes just next to the slider, trying to hit the slider, the scrollview scrolls. I would like to enlarge the area of the slider if possible, or just disable scrolling for a certain part of the scroll view.
Is this possible, and if yes, how?
Thanks...

You need to look at the following properties for customizing the look of a scroll view:
indicatorStyle
scrollIndicatorInsets
Or if this isn't to your taste: You could subclass UIScrollView and when the custom slider receives touches, read them in transform them and call setContentOffset on the UIScrollView. In my opinion that seems like a big task for very little reward and I'd just stick with the default behaviour/look.

Related

UIScrollView start scrolling threshold

I'm looking for a way of 'sticking' a UIScrollView to it's position unless the touch has been moved by a certain threshold, at which point it will jump to where it should have scrolled to and continue scrolling.
The reason for this is that I have a vertical scroll and each cell inside the UIScrollView has a horizontal scroll. So I'd like to introduce a slight 'stickyness' to make sure the user doesn't accidentally scroll vertically when they mean to scroll horizontally.
I started by hijacking the contentOffset property in scrollViewDidScroll. The trouble with that is I cannot find out how much the scrollView would have moved by if I were setting the contentOffset
If I try to add a UIPanGestureRecognizer to the class then it overrides the UIScrollView and the UIScrollView becomes unresponsive.
Does anyone know a way to do this?
EDIT: edits based on comments.

How to implement an auto scroll view like notification center's stock ticker?

I want to implement a scroll view which looks like the stock ticker. It can respond slide or tap gesture.
How can I implement this? Please advise me. Thank you!
Use a NSTimer to reposition the contentOffset of your Scrollview.
Use the UIScrollViewDelegate to stop your animation while the user is dragging the scrollview.
Conceptually I'd setup an container UIScrollView with the contents of the scrolling area as subviews. To simulate a circular scroll I'd keep an array of the subviews. I'd add a view just off screen at the starting edge, and take away a view just off screen at ending edge.
UIScrollViewDelegate methods will be called when a person starts or stops dragging the view, which you can use to start and stop the animated scrolling. Other methods in this protocol can be used to reset the contents of the scrollview when the edge is reached, so more views can be added as needed.
I'd probably use a CADisplayLink to manually manage the animations. The method given to the CADisplayLink would update the scroll and manage adding and subtracting views to the edges. It would also stop scrolling based on a flag set by the UIScrollViewDelegate methods when the person is dragging the scroll.
Unless you jailbreak, you can't put custom views in Notification Centre.

Second UIScrollView responding when using a UIScrollView

This is more of a check as I believe this is right but its a lot of work if I'm wrong.
I want to basically achieve fixed positioning with a scrollView. I want to have a list along the top that is always visible, scrolls horizontal only and then a scrollview beneath that to move around the information which scrolls both vertically and horizontally.
I figure I need to subclass UIScrollView and overwrite touchesBegan, touchesMoved and touchesEnded to send the touch to both UIScrollViews.
Is this right or off track?
Cheers
Overriding the touch events on a scroll view is probably not what you want to do. Instead you can simply use a single scroll view, and then in the parent view's -layoutSubviews or in the scroll view's delegate methods you can move the list so it's always at the same vertical position (use the scroll view's contentOffset property to determine where that should be). Both the delegate method and -layoutSubviews is called before the drawing actually occurs after the scroll view scrolls, so by always repositioning your view where you want it to be, it will appear to remain fixed to the user.

iPhone - strange issue with UIScrollView and touches

I have two UIImageView objects inside my view (both 320x480 one above the other). The lower image view is inside a UIScrollView with scrolling and zooming enabled. Now I want to handle touches inside the other image view but it no longer detects any single taps.
I can understand that the UIScrollView handles all the touches which I do on it. But the touches on the image view above the scroll view are also not recognized.
Attached is an image with my view hierarchy. Can someone please tell me why the other image view's touches are also handled by the scrollview when it isn't a subview of scroll view?
And if the scrollview is bent on handling touches, how do I recognize touches on the other image view?
Thanks.
By default UIImageViews have userInteractionEnabled=NO;
Try setting it to YES (either in IB or in code).
I'm not sure, it might be that you need to set the frame size and/or content size of the scroll view properly. This page has a diagram of what I'm talking about.

UIScrollView not scrolling when set to a tableView's tableHeaderView

I'm having difficulty scrolling a UIScrollView instance in my UITableView when I set it as a tableHeaderView.
It still responds to touch events it appears, but doesn't wish to scroll horizontally. I've tried explicitly setting to setUserInteractionEnabled:YES without much luck.
Is there something in particular I need to do to get scrolling working when this is set as a tableHeaderView?
Thanks.
You probably need to check your scrollView.contentSize, ensure scrollView.contentSize.width > bound width.
This embeds a UIScrollView inside a UIScrollView (since UITableView is a UIScrollView). You probably want to set the tableview's canCancelContentTouches to NO so it doesn't cancel your UIScrollView's touches. That may create some problems if your UITableView needs to scroll vertically.
If that is your issue, subclass UITableView to overload touchesShouldCancelInContentView: so that this does not return YES for horizontal drags (or perhaps for touches in the header).