iOS Guides | Samples

MonoTouch.UIKit.UIDynamicAnimator Class

Coordinates the UIKit Dynamics of a set of IUIDynamicItems and UIDynamicBehaviors.

See Also: UIDynamicAnimator

Syntax

[MonoTouch.Foundation.Register("UIDynamicAnimator", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 7, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
public class UIDynamicAnimator : NSObject, IEnumerable<UIDynamicBehavior>

Remarks

The dynamic animator is responsible for coordinating physics simulations attached to a UIView. These physics simulations are implemented as subclasses of the UIDynamicBehavior class, and include various predefined simulations for gravity, collision detection, attaching, snapping, forces and controling item properties.

UIDynamicAnimator It provides the overall context for managing the physics simulation attached to a UIView. Additionally, it defines the coordinate system for the dynamics and wraps the underlying animation engine. Finally, it keeps track of the UIDynamicBehaviors and IUIDynamicItems that define the particular behaviors and items for which dynamics are desired.

Adding behaviors to a dynamic animator will cause the behavior to run as part of the physics simulation that UIKit runs. To stop a behavior from running (and be part of the simulation), you must remove the behavior from the dynamic animator (use UIDynamicAnimator.RemoveBehavior or UIDynamicAnimator.RemoveAllBehaviors.

It is the application developer's responsibility to create a configuration that can be solved by the physics-like behavior of UI Dynamics.

The following example shows how you can add a couple of behaviors to an animator:

C# Example

public override void ViewDidLoad ()
{
	base.ViewDidLoad ();

	// Create a dynamic animator for the specified UIView
	// in this case, the property "View" of UIViewController
	//
	animator = new UIDynamicAnimator (View);
	
	// Creates two dynamic behaviors

	// Create a gravity behavior that operates on the `square' UIView
	var gravityBehavior = new UIGravityBehavior (square);

	// Create a collision behavior that operates on the same `square' UIVew
	var collisionBehavior = new UICollisionBehavior (square) {
		TranslatesReferenceBoundsIntoBoundary = true
	};

	// Detect collision, hook up to the events raised by that behavior
	collisionBehavior.BeganBoundaryContact += BeganContact;
	collisionBehavior.EndedBoundaryContact += EndedContact;

	// Add the two behaviors to the dynamic animator
	animator.AddBehaviors (gravityBehavior, collisionBehavior);

	// The simulation will start running
}

These are the predefined behaviors that extend the UIDynamicBehavior class: UIAttachmentBehavior, UICollisionBehavior, UIDynamicItemBehavior, UIGravityBehavior, UIPushBehavior and UISnapBehavior.

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.UIDynamicAnimator are listed below.

See Also: NSObject

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
BehaviorsUIDynamicBehavior[]. Array containing the current list of behaviors running on this UIDynamicAnimator.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
DelegateUIDynamicAnimatorDelegate. An instance of the MonoTouch.UIKit.UIDynamicAnimatorDelegate model class which acts as the class delegate.
[read-only]
ElapsedTimeDouble. The time interval since the UIDynamicAnimator began running.
[read-only]
ReferenceViewUIView. The UIView that the UIDynamicAnimator was initialized with. Read-only.
[read-only]
RunningBoolean. Whether the UIDynamicAnimator is running. Read-only.
WeakDelegateNSObject. An object that can respond to the delegate protocol for this type

Public Methods

Add(UIDynamicBehavior)
Adds the specified behavior.
AddBehavior(UIDynamicBehavior)
Adds the specified behavior to the animator.
AddBehaviors(params UIDynamicBehavior[])
Adds the array of specified behaviors.
GetDynamicItems(RectangleF) : IUIDynamicItem[]
The dynamic items that intersect the specified RectangleF.
GetLayoutAttributesForCell(NSIndexPath) : UICollectionViewLayoutAttributes
The layout attributes for a UICollectionView cell.
GetLayoutAttributesForDecorationView(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
The layout attributes for a UICollectionView decoration view.
GetLayoutAttributesForSupplementaryView(NSString, NSIndexPath) : UICollectionViewLayoutAttributes
The layout attributes for a UICollectioNView supplementary view.
RemoveAllBehaviors()
Removes all of the behaviors attached to this animator.
RemoveBehavior(UIDynamicBehavior)
Removes the specified behavior from the animator.
RemoveBehaviors(params UIDynamicBehavior[])
Removes the listed behaviors from the animator.
UpdateItemUsingCurrentState(IUIDynamicItem)
Reads the current state of a dynamic item, replacing the UIDynamicAnimator's internal representation of that item's state.

Protected Methods

override
Dispose(Boolean)
Releases the resources used by the UIDynamicAnimator object.

Explicitly Implemented Interface Members

UIDynamicAnimator$IEnumerable<UIDynamicBehavior>.GetEnumeratorReturns an enumerator that iterates over the dynamic behaviors in the animator.
UIDynamicAnimator$IEnumerable.GetEnumeratorRetrieves the behaviors via an enumerator.