View

public class View: NSObject

The View class defines a rectangular area on the screen and the interfaces for managing visual content in that area. The View class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The C4 framework also includes a set of standard subclasses that range from simple shapes to movies and images that can be used as-is.

  • A UIView. Internally, View wraps and provides access to an internal UIView.

    Declaration

    Swift

    public var view: UIView = LayerView()
  • The current rotation value of the view. Animatable. - returns: A Double value representing the cumulative rotation of the view, measured in Radians.

    Declaration

    Swift

    public var rotation: Double

    Return Value

    A Double value representing the cumulative rotation of the view, measured in Radians.

  • The view’s primary layer. - returns: A Layer, whose properties are animatable (e.g. rotation)

    Declaration

    Swift

    public var animatableLayer: Layer

    Return Value

    A Layer, whose properties are animatable (e.g. rotation)

  • Initializes a View.

    Declaration

    Swift

    public override init()
  • Initializes a new View from a UIView. - parameter view: A UIView.

    Declaration

    Swift

    public init(view: UIView)

    Parameters

    view

    A UIView.

  • Undocumented

    Declaration

    Swift

    public class View: NSObject
  • Undocumented

    Declaration

    Swift

    public class View: NSObject
  • Initializes a new View with the specifed frame. let f = Rect(0,0,100,100) let v = View(frame: f) canvas.add(v) - parameter frame: A Rect, which describes the view’s location and size in its superview’s coordinate system.

    Declaration

    Swift

    public init(frame: Rect)

    Parameters

    frame

    A Rect, which describes the view’s location and size in its superview’s coordinate system.

  • Returns the receiver’s layer.

    Declaration

    Swift

    public dynamic var layer: CALayer?
  • Returns the receiver’s frame. Animatable.

    Declaration

    Swift

    public var frame: Rect
  • Returns the receiver’s bounds. Animatable.

    Declaration

    Swift

    public var bounds: Rect
  • A Boolean indicating whether subviews, and layers are clipped to the object’s bounds. Animatable.

    Declaration

    Swift

    public var masksToBounds: Bool
  • Returns the receiver’s center point. Animatable.

    Declaration

    Swift

    public var center: Point
  • Returns the receiver’s origin. Animatable.

    Declaration

    Swift

    public var origin: Point
  • Returns the receiver’s frame size. Animatable.

    Declaration

    Swift

    public var size: Size
  • Returns the receiver’s frame width. Animatable.

    Declaration

    Swift

    public dynamic var width: Double
  • Returns the receiver’s frame height. Animatable.

    Declaration

    Swift

    public dynamic var height: Double
  • Returns the receiver’s background color. Animatable.

    Declaration

    Swift

    public var backgroundColor: Color?
  • Returns the receiver’s opacity. Animatable.

    Declaration

    Swift

    public dynamic var opacity: Double
  • Returns true if the receiver is hidden, false if visible.

    Declaration

    Swift

    public var hidden: Bool
  • Returns the receiver’s current transform.

    Declaration

    Swift

    public var transform: Transform
  • Defines the anchor point of the layer’s bounds rect, as a point in normalized layer coordinates - ’(0, 0)’ is the bottom left corner of the bounds rect, ’(1, 1)’ is the top right corner. Defaults to ’(0.5, 0.5)’, i.e. the center of the bounds rect. Animatable.

    Declaration

    Swift

    public var anchorPoint: Point
  • The layer’s position on the z axis. Animatable. The default value of this property is 0. Changing the value of this property changes the the front-to-back ordering of layers onscreen. This can affect the visibility of layers whose frame rectangles overlap. The value of this property is measured in points.

    Declaration

    Swift

    public dynamic var zPosition: Double
  • An optional view whose alpha channel is used to mask the receiver’s content. The mask view’s alpha channel determines how much of the receiver’s content and background shows through. Fully or partially opaque pixels allow the underlying content to show through but fully transparent pixels block that content. The default value of this property is nil. When configuring a mask, remember to set the size and position of the mask layer to ensure it is aligned properly with the layer it masks. The layer you assign to this property must not have a superlayer. If it does, the behavior is undefined.

    Declaration

    Swift

    public var mask: View?
  • Returns true if the receiver accepts touch events.

    Declaration

    Swift

    public var interactionEnabled: Bool = true
  • Adds a tap gesture recognizer to the receiver’s view. let f = Rect(0,0,100,100) let v = View(frame: f) v.addTapGestureRecognizer { location, state in println("tapped") } - parameter action: A block of code to be executed when the receiver recognizes a tap gesture. - returns: A UITapGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addTapGestureRecognizer(action: TapAction) -> UITapGestureRecognizer

    Parameters

    action

    A block of code to be executed when the receiver recognizes a tap gesture.

    Return Value

    A UITapGestureRecognizer that can be customized.

  • Adds a pan gesture recognizer to the receiver’s view. “” let f = Rect(0,0,100,100) let v = View(frame: f) v.addPanGestureRecognizer { location, translation, velocity, state in println(panned) } - parameter action: A block of code to be executed when the receiver recognizes a pan gesture. - returns: A UIPanGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addPanGestureRecognizer(action: PanAction) -> UIPanGestureRecognizer
  • Adds a pinch gesture recognizer to the receiver’s view. “” let f = Rect(0,0,100,100) let v = View(frame: f) v.addPinchGestureRecognizer { scale, velocity, state in println(pinched) } - parameter action: A block of code to be executed when the receiver recognizes a pinch gesture. - returns: A UIPinchGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addPinchGestureRecognizer(action: PinchAction) -> UIPinchGestureRecognizer
  • Adds a rotation gesture recognizer to the receiver’s view. let f = Rect(0,0,100,100) let v = View(frame: f) v.addRotationGestureRecognizer { rotation, velocity, state in println("rotated") } - parameter action: A block of code to be executed when the receiver recognizes a rotation gesture. - returns: A UIRotationGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addRotationGestureRecognizer(action: RotationAction) -> UIRotationGestureRecognizer

    Parameters

    action

    A block of code to be executed when the receiver recognizes a rotation gesture.

    Return Value

    A UIRotationGestureRecognizer that can be customized.

  • Adds a longpress gesture recognizer to the receiver’s view. let f = Rect(0,0,100,100) let v = View(frame: f) v.addLongPressGestureRecognizer { location, state in println("longpress") } - parameter action: A block of code to be executed when the receiver recognizes a longpress gesture. - returns: A UILongPressGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addLongPressGestureRecognizer(action: LongPressAction) -> UILongPressGestureRecognizer

    Parameters

    action

    A block of code to be executed when the receiver recognizes a longpress gesture.

    Return Value

    A UILongPressGestureRecognizer that can be customized.

  • Adds a swipe gesture recognizer to the receiver’s view. let f = Rect(0,0,100,100) let v = View(frame: f) v.addSwipeGestureRecognizer { location, state in println("swiped") } - parameter action: A block of code to be executed when the receiver recognizes a swipe gesture. - returns: A UISwipeGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addSwipeGestureRecognizer(action: SwipeAction) -> UISwipeGestureRecognizer

    Parameters

    action

    A block of code to be executed when the receiver recognizes a swipe gesture.

    Return Value

    A UISwipeGestureRecognizer that can be customized.

  • Adds a screen edge pan gesture recognizer to the receiver’s view. let v = View(frame: canvas.bounds) v.addSwipeGestureRecognizer { location, state in println("edge pan") } - parameter action: A block of code to be executed when the receiver recognizes a screen edge pan gesture. - returns: A UIScreenEdgePanGestureRecognizer that can be customized.

    Declaration

    Swift

    public func addScreenEdgePanGestureRecognizer(action: ScreenEdgePanAction) -> UIScreenEdgePanGestureRecognizer

    Parameters

    action

    A block of code to be executed when the receiver recognizes a screen edge pan gesture.

    Return Value

    A UIScreenEdgePanGestureRecognizer that can be customized.

  • Adds a view to the end of the receiver’s list of subviews. When working with C4, use this method to add views because it handles the addition of both UIView and View. let v = View(frame: Rect(0,0,100,100)) let subv = View(frame: Rect(25,25,50,50)) v.add(subv) - parameter subview: The view to be added.

    Declaration

    Swift

    public func add<T>(subview: T?)

    Parameters

    subview

    The view to be added.

  • Adds an array of views to the end of the receiver’s list of subviews. When working with C4, use this method to add views because it handles the addition of both UIView and View. let v = View(frame: Rect(0,0,100,100)) let subv1 = View(frame: Rect(25,25,50,50)) let subv2 = View(frame: Rect(100,25,50,50)) v.add([subv1,subv2]) - parameter subviews: An array of UIView or View objects to be added to the receiver.

    Declaration

    Swift

    public func add<T>(subviews: [T?])

    Parameters

    subviews

    An array of UIView or View objects to be added to the receiver.

  • Unlinks the view from the receiver and its window, and removes it from the responder chain. Calling this method removes any constraints that refer to the view you are removing, or that refer to any view in the subtree of the view you are removing. When working with C4, use this method to add views because it handles the removal of both UIView and View. let v = View(frame: Rect(0,0,100,100)) let subv = View(frame: Rect(25,25,50,50)) v.add(subv) v.remove(subv) - parameter subview: The view to be removed.

    Declaration

    Swift

    public func remove<T>(subview: T?)

    Parameters

    subview

    The view to be removed.

  • Unlinks the view from its superview and its window, and removes it from the responder chain. If the view’s superview is not nil, the superview releases the view. Calling this method removes any constraints that refer to the view you are removing, or that refer to any view in the subtree of the view you are removing. let v = View(frame: Rect(0,0,100,100)) let subv = View(frame: Rect(25,25,50,50)) v.add(subv) subv.removeFromSuperview()

    Declaration

    Swift

    public func removeFromSuperview()
  • Moves the specified subview so that it appears behind its siblings. - parameter subview: The subview to move to the back.

    Declaration

    Swift

    public func sendToBack<T>(subview: T?)

    Parameters

    subview

    The subview to move to the back.

  • Moves the specified subview so that it appears on top of its siblings. - parameter subview: The subview to move to the front.

    Declaration

    Swift

    public func bringToFront<T>(subview: T?)

    Parameters

    subview

    The subview to move to the front.

  • Checks if a specified point falls within the bounds of the current object. - note: Because each view has its own coordinates, if you want to check if a point from anywhere on screen falls within a specific view you should use hitTest(point, from: canvas). let v = View(frame: Rect(0,0,100,100)) v.hitTest(Point(50,50)) //-> true v.hitTest(Point(50, 101)) //-> false - parameter point: A Point to examine - returns: true if the point is within the object’s frame, otherwise false.

    Declaration

    Swift

    public func hitTest(point: Point) -> Bool

    Parameters

    point

    A Point to examine

    Return Value

    true if the point is within the object’s frame, otherwise false.

  • Checks if a specified point, from another view, falls within the frame of the receiver. let v = View(frame: Rect(0,0,100,100)) canvas.add(v) canvas.addTapGestureRecognizer() { location, state in if v.hitTest(location, from: self.canvas) { println("C4") } } - parameter point: The point to check - parameter from: The view whose coordinate system the point is to be converted from - returns: true if the point is within the object’s frame, otherwise false.

    Declaration

    Swift

    public func hitTest(point: Point, from: View) -> Bool

    Parameters

    point

    The point to check

    from

    The view whose coordinate system the point is to be converted from

    Return Value

    true if the point is within the object’s frame, otherwise false.

  • Converts a specified point from a given view’s coordinate system to that of the receiver. let p = Point() let cp = aView.convert(p, from:canvas) - parameter point: The point to convert - parameter from: The view whose coordinate system the point is to be converted from - returns: A Point whose values have been translated into the receiver’s coordinate system.

    Declaration

    Swift

    public func convert(point: Point, from: View) -> Point

    Parameters

    point

    The point to convert

    from

    The view whose coordinate system the point is to be converted from

    Return Value

    A Point whose values have been translated into the receiver’s coordinate system.

  • Moves the receiver so that it appears on top of the specified view. - parameter view: The view above which the receive will be positioned

    Declaration

    Swift

    public func positionAbove(view: View)

    Parameters

    view

    The view above which the receive will be positioned

  • Moves the receiver so that it appears on below of the specified view. - parameter view: The view below which the receive will be positioned

    Declaration

    Swift

    public func positionBelow(view: View)

    Parameters

    view

    The view below which the receive will be positioned

  • A class-level function that executes an animation using a specified block of code.

    Declaration

    Swift

    public class func animate(duration duration: Double, animations: Void -> Void)

    Parameters

    duration

    The length of time in seconds for the animation to execute.

    animations

    A block of code with specified animations to execute.

  • A class-level function that executes an animation using a specified block of code, with parameters for delaying and completion.

    Declaration

    Swift

    public class func animate(duration duration: Double, delay: Double, animations: () -> Void, completion: (Bool -> Void)?)

    Parameters

    duration

    The length of time in seconds for the animation to execute.

    delay

    The length of time in seconds to wait before executing the specified block of code.

    completion

    A block of code to execute when the animation completes.

    animations

    A block of code with specified animations to execute.

  • A class-level function that executes an animation using a specified block of code, with parameters for delaying, completion and animation options.

    Declaration

    Swift

    public class func animate(duration duration: Double, delay: Double, options: UIViewAnimationOptions, animations: () -> Void, completion: (Bool -> Void)?)

    Parameters

    duration

    The length of time in seconds for the animation to execute.

    delay

    The length of time in seconds to wait before executing the specified block of code.

    options

    Options for animating views using block objects, see: UIViewAnimationOptions.

    animations

    A block of code with specified animations to execute.

    completion

    A block of code to execute when the animation completes.

  • Returns a struct that represents the current visible state of the receiver’s border. Animatable.

    let v = View(frame: Rect(25,25,100,100))
    var b = Border()
    b.width = 10.0
    b.color = C4Purple
    v.border = b
    canvas.add(v)
    

    Assigning a new value to this will change the borderWidth, borderColor and cornderRadius of the receiver’s layer.

    Declaration

    Swift

    public var border: Border
  • Sets the arbitrary keyed-data for the specified key.

    Declaration

    Swift

    public override func setValue(value: AnyObject?, forKey key: String)

    Parameters

    value

    The value for the key identified by .

    key

    The name of one of the receiver’s properties.

  • Returns the arbitrary keyed-data specified by the given key.

    Declaration

    Swift

    public override func valueForKey(key: String) -> AnyObject?

    Parameters

    key

    The name of one of the receiver’s properties.

    Return Value

    The value for the data specified by the key.

  • Creates a flattened image of the receiver and its subviews / layers. - returns: A new Image

    Declaration

    Swift

    public func render() -> Image?

    Return Value

    A new Image

  • Returns a struct that represents the current visible state of the receiver’s shadow. Animatable.

    Assigning a new value to this will change the shadowRadius, shadowColor, shadowOpacity, shadowPath and shadowOffset of the receiver’s layer.

    The path is optional, and only set if it has a value.

    let v = View(frame: Rect(25,25,100,100))
    v.backgroundColor = white
    var s = Shadow()
    s.opacity = 0.5
    v.shadow = s
    canvas.add(v)
    

    Declaration

    Swift

    public var shadow: Shadow