Giter VIP home page Giter VIP logo

kyparallaxview's Introduction

KYParallaxView

CocoaPods Version License Platform

一个 使用简单 / 高度自定义 / 两种使用方法 的视差滚动框架。自定义程度之高、耦合度之低、内存占用程度在同类效果开源框架中是相当优秀的。

it's a easy-to-use / highly customize / two way to use parallax effects framework.

##安装 Installation

pod 'KYParallaxView', '~> 1.0.4'


##本框架有两种使用场景:

Two situations to use this framework:

##1、如果你不需要使用水平滚动的框架,只需要使用效果图中单页垂直滚动效果,那么你只需在你的ViewController中。

 If you just wanna use the single vertical scroll view,you should:

#import "KYParallaxVerticalView.h"

    KYParallaxVerticalView *parallaxVerticalView= [[KYParallaxVerticalView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:parallaxVerticalView];
    [parallaxVerticalView bkgImageViewSetImage: [UIImage imageNamed:@"[email protected]"]];// 指定背景图
就可以了。

That's it!

##2、如果你需要使用整个框架,那么你需要在你的ViewController中:

 If you wanna use the whole framework.

#import "KYParallaxHorizontalView.h"

  KYParallaxHorizontalView *parallaxHorizontalView = [[KYParallaxHorizontalView alloc]initWithFrame:self.view.frame andCollectionDelegate:self];
  [self.view addSubview:self.parallaxHorizontalView];
  • 然后实现UICollectionDataSource的协议方法:

    Then implement the UICollectionDataSource's protocol method:

#pragma mark -- UICollectionDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 5;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    KYParallaxCollectionCell *cell = (KYParallaxCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"HorizontalParallexCell" forIndexPath:indexPath];

    /*****自定义cell视图*****/
    /*****Custom the vertical scrollview content******/
    //设置每个单页的背景图片 Set the background img of every vertical scrollview
    [cell.verticalView bkgImageViewSetImage:[UIImage imageNamed:[NSString stringWithFormat:@"bkgImg_%ld.jpg",(long)indexPath.item+1]]];
    cell.verticalView.customView.label.text = [NSString stringWithFormat:@"%ld",(long)indexPath.item+1];
    cell.verticalView.customView.avatar.image = [UIImage imageNamed:[NSString stringWithFormat:@"kitten_%ld",(long)indexPath.item+1]];
    cell.verticalView.customView.pic.image = [UIImage imageNamed:[NSString stringWithFormat:@"l%ld.jpg",indexPath.item+1]];
    cell.verticalView.scroller.contentOffset = CGPointMake(0, 0); //解决cell同时复用scrollview位置的bug  Fix resuing the contentOffset of cell
    
    //...
    
    return cell;
    
}
  • 最后你还需要实现UIScrollViewDelegate中的scrollViewDidScroll方法:

    Lastly,you should mplement the UIScrollViewDelegate's protocol method

#pragma mark -- UITableViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.parallaxHorizontalView parallax:scrollView];
}

##3.如何自定义单页滚动视图内容?

How to customize the vertical scroll view's  content?
  • 你会发现有三个文件. there are three files.

  • 你会发现CustomViewXib是这样的:

    So you can customize your content in the xib.

  • 是的,你可以在这里可视化布局你想要的滚动界面的内容。当然,为了方便自定义内容你还需要把这些视图拖到代码中来:

    Also you can use IBOutlet to connect the xib and the code.

@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIView *box1;
@property (strong, nonatomic) IBOutlet UIView *box2;
@property (strong, nonatomic) IBOutlet UIView *box3;
@property (strong, nonatomic) IBOutlet UIImageView *avatar;
@property (strong, nonatomic) IBOutlet UIImageView *pic;

##版本 ###v1.0.4 使用官方的UICollectionViewFlowLayout,移除自定义Layout。

###v1.0.3 解决了在一个有状态栏的页面使用本框架时UIScrollView会发生偏移的问题。

kyparallaxview's People

Contributors

kittenyang avatar

Watchers

gryphon avatar  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.