Giter VIP home page Giter VIP logo

beziercurveview's Introduction

Swift Bezier Curve View

Build Status CocoaPods Carthage compatible MIT License

Bezier curves are very handy to point to objects in your interface, for onboarding and help screens:

camerahint

Create and edit arrows to light up your interface, with visual preview in Xcode Storyboard and Interface Builder.

Technical Discussion

In Interface Builder, position a BezierCurveView and drop two BezierCurveHandle inside it.

  1. BezierCurveView represents the drawing space. It can be as large as the UIWindow to prevent curve clipping.
  2. BezierCurveHandle represents the two handles required by a Cubic Bezier Curve. It adopts the BezierHandleProtocol, which provides control point information.

The combination BezierCurveView + 2 BezierCurveHandle yields live preview in Interface Builder, with unprecedented flexibility: cameraib. Because a BezierCurveHandle is itself a UIView, it can be controlled by AutoLayout constraints, and thus adapt automatically to changes in sizes and orientations, with exactly 0 lines of code. And since these handles are themselves extensions to the BezierHandleProtocol, you can tailor any of your UIView subclasses to control handles as well.

Notes

  1. Make sure that a BezierCurveView contains exactly two subviews adopting BezierHandleProtocol for any drawing to take place
  2. In most situations, BezierCurveView and BezierCurveHandle background color should be clear
  3. BezierCurveView will be refreshed any time its frame is updated, providing dynamic animations: bezierelasticity (replay)

Bezier Curve View Properties

IBInspectable What it does
lineWidth bezier curve thickness ; default is 1.5
tintColor color of the curve ; defaults to black if absent

Bezier Handle View Properties

IBInspectable What it does
dx horizontal component of the control point ; default is 0
dy vertical component of the control point ; default is -10.0 (control point is 10.0 pixels below the anchor
shape one of none, arrowHead, circle or disc, default is none
size dimensions of the shape: a shaft length for the arrow, a radius for circles and discs (โ€ ) ; default is 15.0

(โ€ ) The bezier curve end point is adjusted to start from the end of the shape

Installation

Use Cocoapods or include the source file directly. Cocoapods preferred.

API Compatibility: version 4.x introduces BezierHandleProtocol, BezierHandleView and BezierCurveView, deprecating 3.x BezierCurveArrowView.

Demo

Run pod install in the BezierCurveExample directory, open BezierCurveExample.xcworkspace and run. beziercurveviewstoryboard

Getting Help

Search for BezierCurveView answers on Stack Overflow, or ask questions to be adressed by the community. You can also contact the author.

beziercurveview's People

Contributors

swiftarchitect avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

vamsirajendra

beziercurveview's Issues

Potential memory leak reported by Static Analyzer

BezierCurveArrowViewObjC7.m:97:9: Potential leak of an object stored into 'headPath'
BezierCurveArrowViewObjC7.m:56:8: Assuming 'context' is non-null
BezierCurveArrowViewObjC7.m:82:43: Call to function 'CGPathCreateMutable' returns a Core Foundation object with a +1 retain count
BezierCurveArrowViewObjC7.m:97:9: Object leaked: object allocated and stored into 'headPath' is not referenced later in this execution path and has a retain count of +1

Match arrow tip to endpoint

The arrow tip is drawn beyond the endControl control point. This prevents other kind of tips (circle, target, image) since the bounds of the bezier curve is not predictable.

Proposal:

Draw arrow's tip at the endControl location, and connect the curve to it.

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.