Questions tagged [uidynamicanimator]

A dynamic animator provides physics-related capabilities and animations for its dynamic items, and provides the context for those animations.

A dynamic animator provides physics-related capabilities and animations for its dynamic items, and provides the context for those animations.

It does this by intermediating between the underlying iOS physics engine and dynamic items, via behavior objects you add to the animator.

A dynamic item is any iOS or custom object that conforms to the UIDynamicItem protocol. The UIView and UICollectionViewLayoutAttributes classes implement this protocol starting in iOS 7.0. You can implement this protocol to use a dynamic animator with custom objects for such purposes as reacting to rotation or position changes computed by an animator.

To use dynamics, configure one or more dynamic behaviors—including providing each with a set of dynamic items—and then add those behaviors to a dynamic animator.

You specify dynamic behaviors using any of the iOS primitive dynamic behavior classes: UIAttachmentBehavior, UICollisionBehavior, UIDynamicItemBehavior, UIGravityBehavior, UIPushBehavior, and UISnapBehavior. Each of these provides configuration options and lets you associate one or more dynamic items to the behavior. To activate a behavior, add it to an animator.

A dynamic animator interacts with each of its dynamic items as follows:

  • Before adding an item to a behavior, you specify the item’s starting position, rotation, and bounds (to do so, use properties of the item’s class, such as the center, transform, and bounds properties in the case of a UIView-based item)

  • After you add the behavior to an animator, the animator takes over: it updates the item’s position and rotation as animation proceeds (see the UIDynamicItem protocol)

  • You can programmatically update an item’s state in the midst of an animation, after which the animator takes back control of the item’s animation, relative to the state you specified (see the updateItemUsingCurrentState: method)

You can define composite behaviors using the addChildBehavior: method of the UIDynamicBehavior parent behavior class. The set of behaviors you add to an animator constitute a behavior hierarchy. Each behavior instance you associate with an animator can be present only once in the hierarchy.

To employ a dynamic animator, first identify the type of dynamic items you want to animate. This choice determines which initializer to call, and this in turn determines how the coordinate system gets set up. The three ways to initialize an animator, the dynamic items you can then use, and the resulting coordinate system, are as follows:

  • To animate views, create an animator with the initWithReferenceView: method. The coordinate system of the reference view serves as the coordinate system for the animator’s behaviors and items. Each dynamic item you associate with this sort of animator must be a UIView object and must descend from the reference view.

You can define a boundary, for items participating in a collision behavior, relative to the bounds of the reference view. See the setTranslatesReferenceBoundsIntoBoundaryWithInsets: method.

  • To animate collection views, create an animator with the initWithCollectionViewLayout: method. The resulting animator employs a collection view layout (an object of the UICollectionViewLayout class) for its coordinate system. The dynamic items in this sort of animator must be UICollectionViewLayoutAttributes objects that are part of the layout.

You can define a boundary, for items participating in a collision behavior, relative to the bounds of the collection view layout. See the setTranslatesReferenceBoundsIntoBoundaryWithInsets: method.

A collection view animator automatically calls the invalidateLayout method as needed, and automatically pauses and resumes animation, as appropriate, when you change a collection view’s layout.

  • To employ a dynamic animator with other objects that conform to the UIDynamicItem protocol, create an animator with the inherited init method. The resulting animator employs an abstract coordinate system, not tied to the screen or to any view.

There is no reference boundary to refer to when defining a collision boundary for use with this sort of animator. However, you can still, in a collision behavior, specify custom boundaries as described in UICollisionBehavior Class Reference.

All types of dynamic animators share the following characteristics:

  • Each dynamic animator is independent of other dynamic animators you create

  • You can associate a given dynamic item with multiple behaviors, provided those behaviors belong to the same animator

  • An animator automatically pauses when all its items are at rest, and automatically resumes when a behavior parameter changes or a behavior or item is added or removed

You can implement a delegate to respond to changes in animator pause/resumption status, using the dynamicAnimatorDidPause: and dynamicAnimatorWillResume: methods of the UIDynamicAnimatorDelegate protocol.

Reference: https://developer.apple.com/library/ios/documentation/uikit/reference/UIDynamicAnimator_Class/Reference/Reference.html

61 questions
13
votes
2 answers

UIDynamicAnimator + custom UICollectionViewLayout resulting in perpetual circular motion

I've been replicating the 2013 WWDC Session 217 "Exploring Scroll Views on iOS 7". I'm using Xcode 7 beta 2 and my project is iOS 9 only. I’m trying to use a UIDynamicAnimator with my UICollectionViewLayout in a way similar to the one presented in…
Goles
  • 11,599
  • 22
  • 79
  • 140
8
votes
2 answers

Animating with UIDynamicAnimator when Autolayout is in play

I have a ViewController that has been configured in InterfaceBuilder to use AutoLayout for all of its subviews. Layout is working fine. I want to make one of the subviews bounce using the cool gravity effects provided by UIDynamicAnimator. I didn't…
stone
  • 8,422
  • 5
  • 54
  • 66
3
votes
1 answer

How to push dynamic object with same speed using UIPushBehavior?

I'm not a physics expert. However, I want to move UILable which has a dynamic height (depends on content) just like teleprompter. But when I start behaviour with magnitude 10, it starts moving but suddenly its slow down and I want continuous move…
Sunil Targe
  • 7,251
  • 5
  • 49
  • 80
3
votes
1 answer

UICollisionBehavior boundary not working

I've got a view within a navigation controller. I am then adding a subview to this view and offsetting its origin height so that it covers only half the screen (with the other half overflowing off out the bottom of the screen). I want to be able to…
myles
  • 1,681
  • 1
  • 15
  • 27
3
votes
1 answer

Swift: UIDynamic animate panel from bottom to top

I want to build a simple custom view which slides up from the bottom with UIDynamicAnimator. When the app loads I offset the view from the screen using: panelWidth = originView!.frame.size.width panelHeight =…
Halfpint
  • 3,967
  • 9
  • 50
  • 92
3
votes
1 answer

iOS how to calculate transition duration when using UIDynamicAnimator for view controller transitions?

I'm modifying this example of using dynamic animators for view controller transitions. One of the things I want to do is make it work on iPad and change the direction of gravity transition from top down to right to left. I'm interested if there is a…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
3
votes
1 answer

Performance Issue With UIKit Dynamics

Recently when I was playing with Stuart Hall's tutorial for UIKit Dynamics (http://stuartkhall.com/posts/flipcase-bounce-in-uikit-dynamics), I found there was a performance issue. After I added about 50 items (bouncing balls) to the animator, the…
Yuchen Wang
  • 1,682
  • 2
  • 14
  • 16
3
votes
3 answers

Disabling Vertical movement of UIAttachmnetBehavior in UICollectionView

Im trying mimic messages app spring animation in a horizontal UICollectionView I have used UIAttachmentBehavior in my UICollectionViewFlowLayout subclass. but the problem is that as I scrolls horizontally, cells also move vertically and horizontally…
3
votes
1 answer

UIKit Dynamics collision - keeping the Barriers elements stationary

How do I prevent the "Barrier"s which are the red elements from moving - while allowing the "falling" elements (Gray / UIView* square) to fall and interact with the barrier(s)? There are many gray elements, many red barriers... @interface…
chewy
  • 8,207
  • 6
  • 42
  • 70
2
votes
0 answers

UIPushBehavior in swift

I want to implement a UIPushBehavior in Swift, but I 'm always getting following error: ... View item UIImageView should be a descendant of reference view in UIDynamicAnimator ... I 'm adding the view to the behavior and the behavior to the…
2
votes
1 answer

How do i add dynamic behaviour in NSObject class : Swift

I'm trying to create a custom alertview with dynamic behaviour using UIDynamicAnimator in NSObject class using swift,While adding UISnapBehaviour to a view in NSObject class init method snap behaviour is not working,For instance look at the below…
Gokul G
  • 2,046
  • 15
  • 22
2
votes
0 answers

I'm having performance problems with using UIDynamicAnimations and creating and deleting items

I made an app based on UIDynamicBehavior. It's a game where you have a circle in the middle of the screen and there are balls launching out of the middle to the outer circle (when they hit it they disappear) where the interval between this…
user2724677
2
votes
1 answer

Remove Oscillation from UIAttachmentBehavior in UICollectionView

I am attempting to recreate the spring behavior that you see in the iOS Messages app in my UICollectionView. Like Messages it will have various cell sizes based on the text size. I have created a custom UICollectionViewFlowLayout which does add the…
2
votes
0 answers

Resizing a UIDynamicItem

Is there a simple way to handle the resizing of a UIView controlled by UIKit Dynamics? I am aware of UIDynamicAnimator's updateItemUsingCurrentState: method, but the documentation seems to point out that this is for position and rotation changes…
Clafou
  • 15,250
  • 7
  • 58
  • 89
2
votes
2 answers

iOS7 how to understand UIPushBehavior magnitude in UIPushBehaviorModeInstantaneous mode?

I'm looking at Apple documentation for UIPushBehavior and it confuses me in instantaneous mode. I know that the acceleration formula is Force = Mass * acceleration. I assume that mass of a view is width*height*density(1). The documentation describes…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
1
2 3 4 5