iOS Guides | Samples

MonoTouch.UIKit.UIFieldBehavior Class

A UIDynamicBehavior that models a field, such as gravity, electricity, or turbulence.

See Also: UIFieldBehavior

Syntax

[MonoTouch.Foundation.Register("UIFieldBehavior", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 9, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
public class UIFieldBehavior : UIDynamicBehavior

Remarks

UIFieldBehavior objects apply a force vector to one or more IUIDynamicItem objects (such as UIView objects). The vector depends on the type of field generated, as shown in the following:

A UIFieldBehavior only applies to the IUIDynamicItem objects in its UIFieldBehavior.Items array. The following example creates a vortex field centered in the main screen. The field applies to each of the items in the wanderers array of UIView objects. Once the UIFieldBehavior is created and applied to the UIDynamicItemBehavior objects associated with the views in wanderers, the behavior is added to the UIDynamicAnimator.

F# Example

let fieldBehavior = UIFieldBehavior.CreateVortexField()
fieldBehavior.Position <- new CGPoint(this.View.Frame.Left + this.View.Frame.Width / nfloat 2.0, this.View.Frame.Top + this.View.Frame.Height / nfloat 2.0)
fieldBehavior.MinimumRadius <- nfloat 5.0

let animator = new UIDynamicAnimator(this.View)

let wanderers = 
    seq { 20.0 .. 60.0 .. (Math.Floor(float frame.Height)) }
    |> Seq.map (fun y -> new CGRect(20.0, y, 20.0, 20.0))
    |> Seq.map (fun frame -> 
        let v = new UIView(frame)
        v.BackgroundColor <- UIColor.Red
        v
        ) |> Array.ofSeq
this.View.AddSubviews(wanderers)

wanderers 
|> Seq.map (fun w -> new UIDynamicItemBehavior([| w :> IUIDynamicItem|])) 
|> Seq.iter (fun itemBehavior ->
    itemBehavior.Density <- nfloat 0.01
    itemBehavior.Resistance <- nfloat 0.0
    itemBehavior.Friction <- nfloat 0.0
    itemBehavior.AllowsRotation <- true
    itemBehavior.Charge <- nfloat -1.0
    animator.AddBehavior(itemBehavior)
    )

wanderers |> Seq.iter fieldBehavior.AddItem

animator.AddBehavior(fieldBehavior)

The vortex force vectors are shown here:

Developers may visualize the field with PerformSelector(new ObjCRuntime.Selector("setDebugEnabled:"), Foundation.NSObject.FromObject(true)).

Related content

Requirements

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

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

See Also: UIDynamicBehavior

Public Constructors

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

AnimationSpeedSingle. In noise and turbulence fields, the multiplier for animation.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
DirectionCGVector. The direction of motion in linear and gravity fields.
FalloffSingle. The rate of field diminishment at distances greater than UIFieldBehavior.MinimumRadius.
[read-only]
ItemsIUIDynamicItem[]. The set of IUIDynamicItem objects to which this field applies.
MinimumRadiusSingle. Objects closer than this distance are calculated as if they were at this minimum distance.
PositionPointF. The location of the center of the field, in view coordinates.
RegionUIRegion. This, with UIFieldBehavior.Position, determines the limits of the field's effects.
SmoothnessSingle. In noise or turbulence fields, the amount of noise or turbulence, in the range 0 (maximum) to 1 (minimum).
StrengthSingle. The strength of the field, in arbitrary units that differ among fields

Public Methods

AddItem(IUIDynamicItem)
Adds the to this UIFieldBehavior.
static
CreateCustomField(UIFieldCustomEvaluator) : UIFieldBehavior
Creates a custom field defined by .
static
CreateDragField() : UIFieldBehavior
Factory method to create a field that mimics drag.
static
CreateElectricField() : UIFieldBehavior
Factory method to create a field that mimics an EM field interacting with UIDynamicItemBehavior.Charge.
static
CreateLinearGravityField(CGVector) : UIFieldBehavior
Factory method to create a field that mimics gravity pulling in a single direction.
static
CreateMagneticField() : UIFieldBehavior
Factory method to create a field that mimics gravity pulling in a single direction.
static
CreateNoiseField(Single, Single) : UIFieldBehavior
Factory method to create a field with random forces.
static
CreateRadialGravityField(PointF) : UIFieldBehavior
Factory method to create a field that attracts objects to a point.
static
CreateSpringField() : UIFieldBehavior
Factory method to create a field that acts like a spring.
static
CreateTurbulenceField(Single, Single) : UIFieldBehavior
Factory method to create a field that simulates turbulence.
static
CreateVelocityField(CGVector) : UIFieldBehavior
Factory method to create a field that applies a linear velocity to affected items.
static
CreateVortexField() : UIFieldBehavior
Factory method to create a spiraling field.
RemoveItem(IUIDynamicItem)
Removes from UIFieldBehavior.Items.