I am trying to make an effect similar to that found in the new Yahoo weather app. Basically, each page in the UIPageViewController
has a background image, and when scrolling through the page view, the Image's location only scrolls about half the speed. How would I do that? I thought I could use some sort of Delegate Method in the UIPageViewController
to get the current offset and then update the images like that. The only problem is that I cannot find anyway to tell if the UIPageViewController
is being scrolled! Is there a method for that? Thanks!
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- SwiftUI: UIImage (QRCode) does not load after call
- iOS (objective-c) compression_decode_buffer() retu
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
Using:
I would do this:
Objective-C
and implement this protocol
Swift
and implement this protocol
In Swift 3 you could write it even shorter:
Use @Paul's snippet -
to implement this protocol :
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
This gives you the percentage completion of the scroll. Happy coding!
What you are looking for is called parallax scrolling, you can find several libraries that can help you with that.
Edit: Matt is right this is not an answer, only a hint. Anyway let's complete it:
For animating a background image that lay behind your UIPageViewController you should use the delegate methods that it offer:
With these two methods you can calculate the percentage of the scrolling (you should store your controllers in your array to know at which controller you scrolled to and get the percentage)
this gives you access to all standard scroll view API methods. And this is not using private Apple API's.
I added traversing through subviews, to 100% find the
UIPageViewController
's inner scroll view WARNING: Be careful with scrollview.contentOffset. It resets as the controller scrolls to new pagesIf you need persision
scrollview
offset tracking and stuff like that, it would be better to use aUICollectionViewController
with cells sized as the collection view itself and paging enabled.