animationios7uikituikit-dynamics

Disable rotation on a UISnapBehavior?


I like that UISnapBehavior snippet, but I really want to use it to slide in one direction only with a slight oscillation.

Is there a way to turn off rotation for this behavior? As SpriteKit has allowsRotation property which can be easily turned off.


Solution

  • You can do this by adding a UIDynamicItemBehavior to your UIDynamicAnimator and then setting its allowsRotation property to NO like so:

    UIDynamicItemBehavior * dynamicItem = [[UIDynamicItemBehavior alloc] initWithItems:@[self.viewToSnap]];
    dynamicItem.allowsRotation = NO;
    [self.animator addBehavior:dynamicItem];