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.
Related
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.
I'm working on a control that looks like a wheel and is used for fast or precise scrolling of content. Here's an example from coach's eye app:
My first take looks like this:
Currently the vertical lines are implemented as set of UIViews. Sure enough these vertical line views could be easily replaced with image views to customise the look.
Each time user pans:
I modify frame.origin.x on all of the vertical line views
If some of the views go off screen - I remove them
If there's a gap on the left or on the right I create new views to fit the place
When user finishes the pan gesture, I start repeat NSTimer (with like 0.05 of a second) to animate decelerating of wheel movement. On each loop of timer in a nutshell:
Calculate distance to move lines and move them
Calculate velocity deceleration amount and adjust the velocity
A couple of questions:
Are there any iOS frameworks (e.g. CoreGraphics, CoreAnimation, UIKitDynamics) that are suited better for implementing these tasks than UIKit APIs I have used?
Can you suggest a better / more correct way to implement "infinite scrolling wheel" control ?
Can you suggest a better way to implement deceleration after user finishes panning the wheel?
Thanks
I had made my "infinite scrolling wheel" control by customizing SSRollingButtonScrollView. I think you should look at it once. I hope it will help you.
Apple already have a nice algorithm implemented for acceleration and deceleration - in UIScrollView. And you can use that, behind the scenes, to control other views / interaction. This is enabled by connecting the pan gesture from the scroll view to another view and acting as the delegate of the scroll view.
Check out the Enhancing User Experience with Scroll Views WWDC video for guidance.
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.
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.
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