Giter VIP home page Giter VIP logo

photostackview-swift's Introduction

#PhotoStackView with swift

###Statement

I studied from an open-sourced code whose name is also "PhotoStackView". But I can't find it now. It is written by Objective-C. Here I rewrite it with swift and fix some small bugs. Also I add some function on it.

###Usage

Just like UITableViewDelegate, you can init PhotoStackView and set the delegate and dataSource of it. Then you must implement the dataSource method func numberOfPhotosInStackView(stackView: PhotoStackView) -> Int and func stackView(stackView: PhotoStackView, imageAtIndex index: Int) -> UIImage to provide data for this view. Alternatively, you can implement optional func stackView(stackView: PhotoStackView, sizeOfPhotoAtIndex index: Int) -> CGSize to specify the size for each image.

To response to some event on this control, you can either implement these optional delegate method:

@objc protocol PhotoStackViewDelegate: NSObjectProtocol {
    optional func stackView(stackView: PhotoStackView, didSelectPhotoAtIndex index: Int)
    optional func stackView(stackView: PhotoStackView, willBeginDraggingPhotoAtIndex index: Int)
    optional func stackView(stackView: PhotoStackView, didRevealPhotoAtIndex index: Int)
    optional func stackView(stackView: PhotoStackView, willFlickAwayPhotoFromIndex from: Int, toIndex to: Int)
}

or use addTarget:action:forControlEvents: to add action listener. All control events it support are TouchDown, TouchCancel, TouchDragInside and TouchUpInside.

###Example

//declare some properties
var photos = [UIImage(named: "github_1.jpeg"), UIImage(named: "github_2.jpeg"), UIImage(named: "github_3.jpeg")]

let ps = PhotoStackView()

//viewDidLoad()
ps.delegate = self
ps.dataSource = self
ps.frame = CGRect(x: 120, y: 50, width: 80, height: 80)
view.addSubview(ps)

ps.addTarget(self, action: Selector("touchDown"), forControlEvents: .TouchDown)

//touchDown action listener
func touchDown() {
    println("touchDown")
}

//data source
func numberOfPhotosInStackView(stackView: PhotoStackView) -> Int {
    return photos.count
}

func stackView(stackView: PhotoStackView, imageAtIndex index: Int) -> UIImage {
    return photos[index]!
}

func stackView(stackView: PhotoStackView, sizeOfPhotoAtIndex index: Int) -> CGSize {
    return CGSizeMake(80, 80)
}

//delegate
func stackView(stackView: PhotoStackView, willFlickAwayPhotoFromIndex from: Int, toIndex to: Int) {
    println("from \(from) to \(to)")
}

###Images

Move, add and delete. stackView1

Show next page stackView2

Show all photos stackView3

photostackview-swift's People

Contributors

ijoyc avatar

Watchers

James Cloos 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.