So I am using UI Kit Dynamics to create a slider which can be swiped out of the way to reveal what is behind it. I am using two UIFieldBehaviour's, an attachment behaviour attached to a UIPanGestureRecognizer, and UICollisionBehaviour to achieve this. The structure in Interface Builder looks like this: Here an image of my view hierarchy
The TrayContainerView has constraints applied to it and it is also the reference view for my DynamicAnimator. trayView is the dynamicItem which dynamicAnimator acts on.
This works fine until I add a subview to trayView from within Interface Builder, at which point I get this message whenever my app switches to that particular viewController:
Terminating app due to uncaught exception 'Invalid Association', reason: 'UIDynamicAnimator supports a maximum of 32 distinct fields'
The strange thing is, if I add the subview programmatically it works fine save for some issues with the layout.
Here's the setup for my dynamics behaviours
container = UICollisionBehavior(items: [self])
let boundaryWidth = UIScreen.mainScreen().bounds.size.width
container.addBoundaryWithIdentifier("upper", fromPoint: CGPointMake(0, offset), toPoint: CGPointMake(boundaryWidth, offset))
let boundaryHeight = self.superview!.frame.size.height + self.frame.size.height - self.layoutMargins.top
container.addBoundaryWithIdentifier("lower", fromPoint: CGPointMake(0,boundaryHeight), toPoint: CGPointMake(boundaryWidth,boundaryHeight))
tractorField = UIFieldBehavior.linearGravityFieldWithVector(CGVectorMake(0, 30))
tractorField.direction = CGVectorMake(0, -10)
let referenceRegion = (superview?.frame)!
let fieldCoefficient:CGFloat = 1
tractorField.region = UIRegion(size: CGSize(width: referenceRegion.width, height: referenceRegion.height*fieldCoefficient))
tractorField.position = CGPointMake((self.superview?.center.x)!, referenceRegion.height*fieldCoefficient/2)
tractorField.addItem(self)
gravityField = UIFieldBehavior.linearGravityFieldWithVector(CGVectorMake(0, 30))
gravityField.direction = CGVectorMake(0, 10)
gravityField.region = UIRegion(size: CGSize(width: referenceRegion.width, height: referenceRegion.height*fieldCoefficient))
gravityField.position = CGPointMake((self.superview?.center.x)!, referenceRegion.height + referenceRegion.height*fieldCoefficient/2)
gravityField.addItem(self)
animator.addBehavior(gravityField)
animator.addBehavior(tractorField)
dynamicItem = UIDynamicItemBehavior(items: [self])
animator.addBehavior(container)
animator.addBehavior(dynamicItem)
any ideas would be greatly appreciated.