2 different scroll view on same window & scroll #different speed - ios

How can i put 2 different scroll view on same window and scroll them at different speed while dragging . one such implementation i recently seen and most of you too might have seen is on the new Yahoo weather app. though there are very good other implementations on few other lesser known apps.

The scrollview on top should have a delegate that knows about both scrollviews. Inside that delegate you should implement the method:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[bottomScrollView setContentOffset:(CGPoint) animated:(BOOL)]
}
Then you will have to calculate how slowly you would like to scroll the second scrollview. Set the CGpoint based of a fraction of the top scrollview's content offset.

Related

Very slow deceleration in UIScrollView just in certain cases

I am struggling with aligning a screen to a certain Views inside a UIScrollView. I would like to have same behaviour as paging (same fast and smooth deceleration) but with alignment to a custom views instead of stoping on multiples of the scroll view’s bounds. I have implemented delegate method scrollViewWillEndDragging(_:withVelocity:targetContentOffset:) in order to define my own scroll view’s bounds location. I have also set decelerationRate to UIScrollViewDecelerationRateFast.
It work mostly as desired except the cases when alignment animation is very slow. To be more precise, sometimes, after the dragging is finished, the scrolling animation decelerates to final point very slowly. It finally reach the correct point but after a longer while. I am not able to track down the cases when it happens. I am able to say that everything works fine when final velocity of dragging is zero. Thus, it happens only in some cases when dragging is finished with nonzero velocity.
I wonder if somebody had same problem since I wasn't able to google anything useful. Can you help me please?
I have solved this problem by implementing delegate methods scrollViewDidEndDragging and scrollViewWillBeginDecelerating. Then by using information from scroll view’s pan gesture I found out about translation and I determined final scroll view’s bounds location using setContentOffset method on scroll view.

iOS UIScrollView with multiple pages visible

I'm having a little issue with scrollview pagination.
My intention is to have 3 pages visible on screen and when I scroll right only on page is scrolled, following the example below, scrolling right will display page 2, 3 and 4 on screen:
However I don't know how to display mutiple pages at the same time, at the moment I have it like this:
Obviously like this is not what I want.
To achieve the desired functionality I tried making the scrollview's frame the size of the page I want (1/3 of the screen width) and setting the clipToBound to NO so the other pages are visible. This indeed shows 3 pages in the screen; however since the scrollview frame is only 1/3 of the screen I can only swipe in that area, I would like the swipe area to be the whole screen width.
You're on the right path. Now you can try manipulating UIPanGestureRecognizer of your scrollView, say, re-attaching it to scrollView's superview.
Alternatively, take a look at iCarousel, it can be perfectly customized to suit your needs.
My solution in the end was the following:
I took my initial approach.
I disabled the scrollview's scrollEnabled property.
Added swipe gesture recognisers to the scrollview.
When the gesture is made I modify the scrollview's contentOffset to move 320/3 pixels to the right or left.

uiscrollview pull horizontal to select object base on how far you drag

I have a uiscrollview and I put 4 uiviews to make an option. I put label 1 for uiview1 and label 2 for uiview2, for uiview 3 i put label 3 and uiview4 i put label 4.
After that I hide the 4 uiview so everytime I pulldown the screen the 4 uiviews will display base on how far the user pull.
Can anyone give an example on how to display the which uiview is selected, when you pull the screen in ios iphone?
You can use contentOffset of scroll View to find how far user pulled scroll View.
Use scroll View delegate Method:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
By checking frames of your views & scrollView contentOffset, you can determine which view is visible (i.e. uiview1, uiview2,..).
Edit:
Your logic should be like this:
if(uiview1.frame.origin.y - scrollView.contentOffset.y > uiview1.frame.origin.y + uiview1.frame.size.height)
{
//your logic for selection of uiview1
}else if.......
Apply this conditions from last view to first view.
For your reference, you can see a sample implementation of a page control from here. http://developer.apple.com/library/ios/#samplecode/PageControl/
For the implementation you want, to your surprise, the scrollview's width is actually smaller than 320 (or 480). The magic property to set is:
scrollView.clipsToBounds = NO
The only problem with this implementation is that the scrollview get no touch events if the touch is outside the bounds of the scrollView. This can be fix by passing its parent hitTest event to scrollView.
Just to link to to a better explanation: UIScrollView horizontal paging like Mobile Safari tabs
Slightly different from what I recommend but does the same thing.
Edit:
I have a small project called LXPagingViews that does the above, hopefully in an out of the box manner (Do drop me a pull request or feedback in issue): https://github.com/lxcid/LXPagingViews

How to create UIScrollView with different page sizes (page snapping, bounce)

I'm trying to create custom vertical UIScrollView which could handle multiple pages with different page heights.
Assumptions:
page height is equal or greater than screen height
if page is taller than screen height, it scrolls as usual UIScrollView – with bouncing on top and bottom
if user ends up scrolling and "page break" is in the middle of screen
if there is no velocity - page snaps to closest
if there is velocity - page changes to one in direction of swipe
I've tried many approaches to achieve this, but I've stumbled upon many UIScrollView quirks, which make it hard.
Problems:
UIPanGestureRecognizer has unreliable method for getting velocity (velocityInView:)
scrollViewWillEndDragging:withVelocity:targetContentOffset: method gives me headache, because it arbitrarily can destroy my attempts to animate setting content offset
I don't know how to achieve bounce in one of the middle pages, I'm afraid i would have to rewrite whole scrolling handling
when I try to override setting content offset when UIScrollView is decelerating, what I get is
my content offset is set
deceleration continues beyond content offset I set
Bonus
I have also tried putting UIScrollView inside UIScrollView as a page, but this approach was also pain in the neck. For example when I was at the bottom of inside scroll, then i scrolled down a bit, put my finger away and quickly grabbed again and scrolled upwards, the outer scroll received touch, which messed up inside scroll presentation.
Does somebody have any idea how to do this? Any tips will be helpful as I'm completely stuck...
Try this. Might help. Based on the Circa news app.
https://www.cocoacontrols.com/controls/rscircapagecontrol

Horizontal Parallax Scrolling UIScrollView iOS

I'm trying to implement horizontal parallax on a paging scroll view which makes it so that one view appears to advance faster in the x direction but "lands" in the same spot (for example, say (0,0)). Here is my general setup / view hierarchy:
(transparent scroller, which intercepts / passes through scroll
events)
(object overlay that I want to move 1.2x pace in the x
direction, but doesn't surpass it's "landing spot")
(another overlay that I want to move at a 1.0x pace in the x
direction)
I know it has to do something with modifying the contentOffset and I have my delegates all setup so that they can all move at the 1x pace in the same direction...any hints as to the solution?
If you want to keep your current setup all you need to do is use the -(void)scrollViewDidScroll:(UIScrollView *)scroller delegate method with your scroller that is tracking the scroll events. In this method you will track the content offset and then use your speed multipliers to move your other views the way you want them to.
However you can easily do this with just 2 scrollviews, and when one moves you track its contentOffset in the same -(void)scrollViewDidScroll:(UIScrollView *)scroller delegate method and move the other accordingly.
Furthermore, if the two scrollviews are of different sizes, a natural parallax effect is incredibly easy to achieve tracking the contentOffset in the -(void)scrollViewDidScroll:(UIScrollView *)scroller delegate method and then using the value and the scrollview's contentSize to get a percentage of how far the scrollview moved and then simply set the contentOffset of the secondary scrollview to scroll that percentage of it's contentSize.
Let me know if you need further explanation.

Resources