Git Product home page Git Product logo

jjpianocontrol's Introduction

JJPianoControl

License MIT  Support 

此灵感来自最美应用APP。

Demo Project


Installation

暂时没有加入Cocoapods 手动引入JJPianoControl文件夹到工程即可使用

Documentation

配置


public struct JJPianoControlConfig {
    
    // 间距
    static var margin               : CGFloat           = 2.0
    
    // 图片内间距
    static var keyPadding           : CGFloat           = 2.0
    
    // 一页显示的最大钢琴键数
    static var numberOfKeysInPage   : Int               = 9
    
    // 钢琴键圆角度数
    static var keyCornerRadius      : CGFloat           = 7.5
    
    // 点击选中的最突出的钢琴键离顶部的距离
    static var pressKeyMaxTop       : CGFloat           = 8.0
    
    // 正常状态的钢琴键高度
    static var nomarlKeyHeight      : CGFloat           = 8.0
    
    // 动画持续时间
    static var animationDuration    : NSTimeInterval    = 0.6
    
    // 取消触屏时延迟时间执行动画
    static var cancelTouchAnimationAfterDelay: NSTimeInterval = 0.5
}

初始化


// config
JJPianoControlConfig.margin = 2.0

// setup UI
let frame   = CGRectMake(0, UIScreen.mainScreen().bounds.height - 54, UIScreen.mainScreen().bounds.width, 54)
let layout  : JJPianoBarFlowLayout  = JJPianoBarFlowLayout()
let bar     : JJPianoBarView        = JJPianoBarView(frame: frame, collectionViewLayout: layout)
bar.registerClass(JJPianoBarCell.self, forCellWithReuseIdentifier: "Cell")
bar.delegate            = self
bar.dataSource          = self
bar.pianoDelegate       = self
bar.autoresizingMask    = [.FlexibleTopMargin]
self.paino              = bar
self.view.addSubview(bar)
bar.scrollTo(0)

代理


// MARK: - JJPianoBarView Delegate
   
func playPiano(from: NSIndexPath, to: NSIndexPath) {
    print("play from:\(from.row) to:\(to.row)")
}

// mark: - UIColletionView Delegate

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell : JJPianoBarCell! = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! JJPianoBarCell
    cell.iconUrl = self.avatars[indexPath.row % avatars.count]
    return cell
}

Requirements

由于采用Swift2.0,该项目最低支持 iOS 8.0。

About

该控制器继承自:UICollectionView

代码还有不足点,比如如何监听scrollToItemAtIndexPath结束后的回调,暂时没找到合适的解决方案。

License

JJPianoControl 使用 MIT 许可证,详情见 LICENSE 文件。

jjpianocontrol's People

Contributors

jrjian avatar

Watchers

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