Code Monkey home page Code Monkey logo

klparallaxview's Introduction

KLParallaxView

KLParallaxView is an Objective-C UIView subclass that imitates Apple TV's parallax effect, based on the similar MPParallaxView Swift implementation.

KLParallaxView

Installation

KLParallaxView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "KLParallaxView"

Example Project

To run the example project, clone the repo and use the workspace in the Example directory, or alternatively run pod try "KLParallaxView" and run the example target.

Usage

KLParallaxView is initialized with an array of subviews whose ordering reflects their positioning in a view hierachy i.e. firstObject is the bottommost view while lastObject is the topmost. By default, KLParallaxView controls each subview's movement during the parallax effect by the value of their tag property.

#import "ViewController.h"
#import "KLParallaxView.h"

@interface ViewController ()

@property (strong, nonatomic) KLParallaxView *parallaxView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
    imageView1.tag = 0;
    UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2"]];
    imageView2.tag = 11;
    UIImageView *imageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3"]];
    imageView3.tag = 2;
    
    NSArray *subviews = @[ imageView1, imageView2, imageView3 ];
    
    self.parallaxView = [[KLParallaxView alloc] initWithFrame:self.view.bounds subviews:subviews];
    [self.view addSubview:self.parallaxView];
}

Configuration

Parallax settings

Set a subview's tag to control how much it moves.

UIImageView *subview = ...
subview.tag = 3;

Use the subviews' positions in the view hierachy rather than their tag property.

self.parallaxView.basedOnHierachy = YES;

Multiply the parallax effect on all views by a given factor.

self.parallaxView.parallaxMultiplier = 2.5;

Multiply the zoom effect on all views by a given factor.

self.parallaxView.zoomMultiplier = 1.5;

Glow settings

Toggle the glowing effect that follows touches.

self.parallaxView.glows = NO;

Change the glow's color.

self.parallaxView.glowColor = [UIColor aqua];

Shadow settings

Change the shadow opacity.

self.parallaxView.shadowOpacity = 0.3;

Change the shadow radius for when the view is not animating.

self.parallaxView.initalShadowRadius = 3.5;

Change the shadow radius for when the view is animating.

self.parallaxView.finalShadowRadius = 9.5;

Change the color of the shadow.

self.parallaxView.shadowColor = [UIColor cerulean];

Other

Set the view's corner radius.

self.parallaxView.cornerRadius = 5.0;

Assets

Taken from MPParallaxView: Thanks Konstantine Trundayev for Interstellar assets!

License

KLParallaxView is available under the MIT license. See the LICENSE file for more info.

klparallaxview's People

Contributors

klop avatar

Watchers

James Cloos avatar Andrei Mistetskiy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.