Skip to content

Instantly share code, notes, and snippets.

@andresbrun
Last active December 21, 2016 12:52
Show Gist options
  • Save andresbrun/ef038379ca2ce58a443f2147b0779c8c to your computer and use it in GitHub Desktop.
Save andresbrun/ef038379ca2ce58a443f2147b0779c8c to your computer and use it in GitHub Desktop.
Shows the different ways to define a attachmentBehaviour
// Dragging an element with a PanGestureRecognizer for instance
let dragAttachmentBehaviour = UIAttachmentBehavior(item: targetView,
offsetFromCenter: offsetFromCenter,
attachedToAnchor: dragLocation)
// Attaching two box in a chain
let boxAttachmentBehaviour = UIAttachmentBehavior(item: box1,
offsetFromCenter: UIOffset(horizontal: 0, vertical: box1.bounds.midY),
attachedTo: box2,
offsetFromCenter: UIOffset(horizontal: 0, vertical: -box2.bounds.midY))
// NOTE: all offsetFromCenter are optional. They are the center of the view by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment