转载

[iOS] 易用、强大的交互式菜单及教程创建工具包类库

TweenController [iOS] 易用、强大的交互式菜单及教程创建工具包类库 [iOS] 易用、强大的交互式菜单及教程创建工具包类库 [iOS] 易用、强大的交互式菜单及教程创建工具包类库 [iOS] 易用、强大的交互式菜单及教程创建工具包类库

On the surface, TweenController makes it easy to build interactive menus and tutorials. Under the hood, it's a simple but powerful toolkit to interpolate between values that are Tweenable .

Example

[iOS] 易用、强大的交互式菜单及教程创建工具包类库

Usage

Tween anything that is Tweenable , such as CGAffineTransform :

func tweenTransform() {     let transformA = CGAffineTransformIdentity     let transformB = CGAffineTransformMakeScale(2.0, 2.0)     let transformC = CGAffineTransformMakeRotation(CGFloat(M_PI_2))      controller.tweenFrom(transformA, at: 0.0)         .to(transformB, at: 0.5)         .thenTo(transformC, at: 1.0)         .withAction(tweenView.layer.twc_applyAffineTransform) }

or UIColor:

func tweenColor() {     let colorA = UIColor.greenColor()     let colorB = UIColor.blueColor()     let colorC = UIColor.redColor()     tweenView.backgroundColor = colorA      controller.tweenFrom(colorA, at: 0.0)         .to(colorB, at: 0.5)         .thenTo(colorC, at: 1.0)         .withAction(tweenView.twc_applyBackgroundColor) }

or your own custom type:

enum Step: Int {     case One = 1, Two = 2, Three = 3, Four = 4 }  extension Step: Tweenable {     static func valueBetween(val1: Step, _ val2: Step, percent: Double) -> Step {         let val = Int(round(Double(val2.rawValue - val1.rawValue) * percent + Double(val1.rawValue)))         return Step(rawValue: max(min(val, 4), 1)) ?? .One     } }  func tweenStep() {     tweenController.tweenFrom(Step.One, at: 0.0)         .to(.Four, at: 0.25)         .thenHoldUntil(0.75)         .thenTo(.Two, at: 1.0)         .withAction { step in             // use step         } }

then simply call:

// can be called in response to user interaction // such as a gesture recognizer or scroll view // or something else, like a CADisplayLink  // progress range is arbitrary // you might choose to use a percentage, like 0.0 - 1.0 // or the content size of a scroll view  controller.updateProgress(newProgress)

You can also observe boundaries :

func observeBoundaries() {     tweenController.observeForwardBoundary(0.5) {          // halfway finished!     }     tweenController.observeBothBoundaries(0.75) {          // this is called when moving backwards or forwards     } }

Standard Tweenables

  • Double
  • Float
  • Int
  • CGFloat
  • CGPoint
  • CGSize
  • CGRect
  • UIColor
  • CGAffineTransform
  • CATransform3D

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate TweenController into your Xcode project using CocoaPods, specify it in your Podfile :

source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks!  pod 'TweenController', '~> 0.1'

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

Carthage

Carthage is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use Homebrew .

$ brew update $ brew install carthage

To integrate TweenController into your Xcode project using Carthage, specify it in your Cartfile :

github "daltonclaybrook/tween-controller" ~> 0.1 

Then, run the following command to build the TweenController framework:

$ carthage update

At last, you need to set up your Xcode project manually to add the TweenController framework.

On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following content:

/usr/local/bin/carthage copy-frameworks 

and add the paths to the frameworks you want to use under “Input Files”:

$(SRCROOT)/Carthage/Build/iOS/TweenController.framework 

For more information about how to use Carthage, please see itsproject page.

Contact

Follow and contact me on Twitter . If you find an issue, justopen a ticket on it. Pull requests are warmly welcome as well.

License

TweenController is released under the MIT license. See LICENSE for details.

原文  https://github.com/daltonclaybrook/tween-controller
正文到此结束
Loading...