Coder Social home page Coder Social logo

yenchenlin / daiexpandcollectionview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daidoujichen/daiexpandcollectionview

0.0 3.0 0.0 426 KB

Expand the current selected item. Focus the user's eyes.

License: MIT License

Ruby 2.54% Objective-C 97.46%

daiexpandcollectionview's Introduction

DaiExpandCollectionView

Expand current selected item and catch users' eyes.

Demo

image

Installation

###CocoaPods DaiExpandCollectionView is available through CocoaPods.

  • Add pod 'DaiExpandCollectionView' to your Podfile
  • Run pod install
  • Run open App.xcworkspace

###Manually Drap 4 source files under floder DaiExpandCollectionView\DaiExpandCollectionView\ to your project.

DaiExpandCollectionView.h
DaiExpandCollectionView.m
DaiExpandCollectionViewFlowLayout.h
DaiExpandCollectionViewFlowLayout.m

and then import the main header file:#import "DaiExpandCollectionView.h"

Overview

Unlike default UICollectionView can only display items with same fixed size, DaiExpandCollectionView can not only display items in two different sizes simultaneously but also change selected items with smooth animation.

How to use

###Step 1 : Init

DaiExpandCollectionView *daiExpandCollectionView = [DaiExpandCollectionView initWithFrame:self.view.bounds];
[daiExpandCollectionView registerClass:[ImageCollectionViewCell class] forCellWithReuseIdentifier:@"ImageCollectionViewCell"];
daiExpandCollectionView.expandDelegate = self;
[self.view addSubview:daiExpandCollectionView];

Note: Init DaiExpandCollectionView using [DaiExpandCollectionView initWithFrame:] instead of [[UICollectionView alloc] initWithFrame:collectionViewLayout:] which used by default UICollectionView.

Next, register UICollectionViewCell and then set up expandDelegate.

###Step 2 : Required delegate methods

There are two required methods in DaiExpandCollectionViewDelegate:

- (NSInteger)numberOfItemsInCollectionView:(UICollectionView *)collectionView;

Return the number of items (views) in the collection view. For example:

- (NSInteger)numberOfItemsInCollectionView:(UICollectionView *)collectionView {
     return 20;
}

means there are 20 items (views) in the collection view.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

Return a UICollectionViewCell to be displayed at the specified index in the collection view. For example:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *identifier = @"ImageCollectionViewCell";
	ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
	cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", indexPath.row + 1]];
	return cell;
}

###Step 3 : Optional delegate methods

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndex:(NSInteger)index;

Return the index of current selected item. For example:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndex:(NSInteger)index {
	NSLog(@"selected : %d", index);
}

Support

  • iOS 7.0+
  • iOS 8.0+ Tested
  • iPhone / iPad
  • Vertical only

daiexpandcollectionview's People

Contributors

daidoujichen avatar yenchenlin avatar

Watchers

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