Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dayitv89/parallax
Parallax effect demo
https://github.com/dayitv89/parallax
Last synced: 9 days ago
JSON representation
Parallax effect demo
- Host: GitHub
- URL: https://github.com/dayitv89/parallax
- Owner: dayitv89
- Created: 2015-03-22T10:24:57.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-11T07:54:02.000Z (about 9 years ago)
- Last Synced: 2023-03-24T08:42:31.071Z (almost 2 years ago)
- Language: Objective-C
- Size: 4.46 MB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Parallax effect demo
[![Build Status](https://travis-ci.org/dayitv89/Parallax.svg?branch=master)](https://travis-ci.org/dayitv89/Parallax)
[![codecov.io](https://codecov.io/github/dayitv89/Parallax/coverage.svg?branch=master)](https://codecov.io/github/dayitv89/Parallax?branch=master)what is Parallax effect?
read from here : http://en.wikipedia.org/wiki/Parallax
But in term of programming, we can simply say varing speed/size of two different visible objects shows parallax effect.
Now a days in web sites and mobile application it is most common attractive point.So How to achieve this?
One point is that just varing speed or size of two visible object, shows parallax effect. So lets assume a situation where scrollview has a image at top and when scroll down it must zoom up to center, and when scroll up image must be vary with different speed (should be slow).
![alt tag](https://raw.githubusercontent.com/gauravds/Parallax/master/HappyHoli.gif)
Just add few lines of codes and we can achieve that :
```
#pragma mark - scroll view delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
CGFloat scrollOffset = scrollView.contentOffset.y;//-- that is image view where we want to show effect
imgView.frame = [self parallaxFrame:imgViewFrame
scrollFrame:scrollView1.frame
withParallaxValue:scrollOffset];
}#pragma mark - parallax effect logic
- (CGRect)parallaxFrame:(CGRect)frame
scrollFrame:(CGRect)scrollFrame
withParallaxValue:(CGFloat)val
{
NSInteger factor = 4;//-- scroll up (slow motion frame up)
if (val > 0) {
return CGRectMake(frame.origin.x, frame.origin.y - val/factor, frame.size.width, frame.size.height);
}// scroll down (must be zoom to center)
return CGRectMake(frame.origin.x + val, frame.origin.y + val, frame.size.width - val*factor, frame.size.height - val*factor);
}```