PMTweenPhysicsUnit Class Reference
| Inherits from | NSObject | 
| Conforms to | PMTweenTempoDelegate PMTweening | 
| Declared in | PMTweenPhysicsUnit.h PMTweenPhysicsUnit.m | 
Overview
PMTweenPhysicsUnit handles a single tween operation on an NSValue property, using a physics system to update a value with decaying velocity.
Tasks
Creating an Instance
- 
	
		– initWithProperty:startingValue:velocity:friction:options:
- 
	
		– initWithObject:propertyKeyPath:startingValue:velocity:friction:options:
Setting Up a Tween
- 
	
		delayproperty
- 
	
		repeatingproperty
- 
	
		numberOfRepeatsproperty
- 
	
		structValueUpdaterproperty
- 
	
		physicsSystemproperty
- 
	
		velocityproperty
- 
	
		frictionproperty
- 
	
		velocityDecayLimitproperty
- 
	
		physicsTimerIntervalproperty
Tween State
- 
	
		targetPropertyproperty
- 
	
		targetObjectproperty
- 
	
		tweenStateproperty
- 
	
		tweenDirectionproperty
- 
	
		startingValueproperty
- 
	
		currentValueproperty
- 
	
		tweenProgressproperty
- 
	
		cycleProgressproperty
- 
	
		cyclesCompletedCountproperty
Notification Blocks
- 
	
		startBlockproperty
- 
	
		stopBlockproperty
- 
	
		updateBlockproperty
- 
	
		repeatCycleBlockproperty
- 
	
		reverseBlockproperty
- 
	
		pauseBlockproperty
- 
	
		resumeBlockproperty
- 
	
		completeBlockproperty
Controlling a Tween
Properties
completeBlock
This notification block is executed when a tween operation has completed (or when all tween cycles have completed, if repeating is set to YES).
@property (nonatomic, copy) PMTweenDidCompleteBlock completeBlockDeclared In
PMTweenPhysicsUnit.hcurrentValue
The current value of the tween operation. (read-only)
@property (readonly, nonatomic, assign) double currentValueDiscussion
@remarks Note that for non-numeric properties like structs this may affect multiple values, such as the x and y properties of CGPoint.
See Also
- @property startingValue, endingvalue 
Declared In
PMTweenPhysicsUnit.hcycleProgress
A float value between 0.0 and 1.0, which represents the current progress of a tween cycle. (read-only)
@property (readonly, nonatomic, assign) CGFloat cycleProgressDiscussion
@remarks This progress could represent one tween or two, depending on whether reversing is set to YES.
Declared In
PMTweenPhysicsUnit.hcyclesCompletedCount
The amount of completed tween cycles. (read-only)
@property (readonly, nonatomic, assign) NSUInteger cyclesCompletedCountDiscussion
@remarks A cycle represents the total length of tweening operation. If reversing is set to YES, a cycle comprises two separate tweens; otherwise a cycle is the length of one tween.
Declared In
PMTweenPhysicsUnit.hdelay
The delay, in seconds, before a tween operation begins.
@property (nonatomic, assign) NSTimeInterval delayDiscussion
Warning: Setting this parameter after a tween operation has begun has no effect.
Declared In
PMTweenPhysicsUnit.hfriction
The current friction coefficient used by the physics system.
@property (nonatomic, assign) double frictionDiscussion
@remarks A value range between 0 and 1, with 1 representing very high friction and 0 representing almost no friction. Setting this property to 0.0 will actually set it a bit fractionally higher than 0 to avoid divide-by-zero errors during calculations.
Declared In
PMTweenPhysicsUnit.hnumberOfRepeats
The number of tween cycle operations to repeat. The default value is 0.
@property (nonatomic, assign) NSUInteger numberOfRepeatsDiscussion
@remarks This property is only used when repeating is set to YES. The default value is 0.
See Also
Declared In
PMTweenPhysicsUnit.hpauseBlock
This notification block is executed when calling the pauseTween method on this instance causes a tween operation to pause.
@property (nonatomic, copy) PMTweenDidPauseBlock pauseBlockSee Also
Declared In
PMTweenPhysicsUnit.hphysicsSystem
An object conforming to the PMTweenPhysicsSolving protocol which solves position calculation updates.
@property (nonatomic, strong) NSObject<PMTweenPhysicsSolving> *physicsSystemDiscussion
@remarks By default, PMTweenPhysicsUnit will assign an instance of PMTweenPhysicsSystem to this property, but you can override this with your own custom classes in order to supply a different physics model.
Declared In
PMTweenPhysicsUnit.hphysicsTimerInterval
Specifies a time step for the physics solver, which is updated independently of tween value updates. The default value calls the physics system 120 times a second, which provides double the precision if your app is rendering at 60 fps.
@property (nonatomic, assign) NSTimeInterval physicsTimerIntervalDeclared In
PMTweenPhysicsUnit.hrepeatCycleBlock
This notification block is executed when a tween cycle has repeated.
@property (nonatomic, copy) PMTweenDidRepeatBlock repeatCycleBlockDeclared In
PMTweenPhysicsUnit.hrepeating
A Boolean which determines whether a tween operation should repeat.
@property (nonatomic, assign) BOOL repeatingDiscussion
@remarks When set to YES, the tween operation repeats for the number of times specified by the numberOfRepeats property. The default value is NO.
See Also
Declared In
PMTweenPhysicsUnit.hresumeBlock
This notification block is executed when calling the resumeTween method on this instance causes a tween operation to resume.
@property (nonatomic, copy) PMTweenDidResumeBlock resumeBlockSee Also
Declared In
PMTweenPhysicsUnit.hreverseBlock
This notification block is executed when this instance’s tweenDirection property changes to PMTweenDirectionReverse.
@property (nonatomic, copy) PMTweenDidReverseBlock reverseBlockSee Also
- @property tweenDirection, reversing 
Declared In
PMTweenPhysicsUnit.hstartBlock
This notification block is executed when calling the startTween method on this instance causes a tween operation to start.
@property (nonatomic, copy) PMTweenDidStartBlock startBlockSee Also
Declared In
PMTweenPhysicsUnit.hstartingValue
The starting value of the tween operation.
@property (nonatomic, assign) double startingValueDiscussion
@remarks Note that for non-numeric properties like structs this may affect multiple values, such as the x and y properties of CGPoint.
See Also
- @property currentValue, endingvalue 
Declared In
PMTweenPhysicsUnit.hstopBlock
This notification block is executed when calling the stopTween method on this instance causes a tween operation to stop.
@property (nonatomic, copy) PMTweenDidStopBlock stopBlockSee Also
Declared In
PMTweenPhysicsUnit.hstructValueUpdater
An object conforming to the PMTweenObjectUpdating protocol which handles the updating of properties on objects and structs.
@property (nonatomic, strong) NSObject<PMTweenObjectUpdating> *structValueUpdaterDiscussion
@remarks By default, PMTweenPhysicsUnit will assign an instance of PMTweenObjectUpdater to this property, but you can override this with your own custom classes if, for instance, you need to tween a value in an object or struct which PMTweenObjectUpdater doesn’t handle.
Declared In
PMTweenPhysicsUnit.htargetObject
The target object whose property should be tweened, applicable if this instance was initiated with the initWithProperty:… method.
@property (readonly, nonatomic, strong) NSObject *targetObjectDeclared In
PMTweenPhysicsUnit.htargetProperty
The property to be tweened.
@property (readonly, nonatomic, strong) NSObject *targetPropertyDeclared In
PMTweenPhysicsUnit.htweenDirection
A PMTweenDirection enum which represents the current direction of the tween operation. (read-only)
@property (readonly, nonatomic, assign) PMTweenDirection tweenDirectionDeclared In
PMTweenPhysicsUnit.htweenProgress
A float value between 0.0 and 1.0, which represents the current progress of a physics deceleration, calculated as the difference between the starting velocity and the current velocity. (read-only)
@property (readonly, nonatomic, assign) CGFloat tweenProgressDeclared In
PMTweenPhysicsUnit.htweenState
A PMTweenState enum which represents the current state of the tween operation. (read-only)
@property (readonly, nonatomic, assign) PMTweenState tweenStateDeclared In
PMTweenPhysicsUnit.hupdateBlock
This notification block is executed when the updateWithTimeInterval:currentTime: method is called on this instance while this instance’s tweenState is PMTweenStateTweening.
@property (nonatomic, copy) PMTweenDidUpdateBlock updateBlockDeclared In
PMTweenPhysicsUnit.hvelocity
The current velocity used by the physics system to calculate tween values, measured in units per second.
@property (nonatomic, assign) double velocityDiscussion
@remarks If you wish to change the velocity after initially setting it via one of the init methods, use this setter. If you change the velocity directly on the physicsSystem object, the tweenProgress property won’t be accurate.
Declared In
PMTweenPhysicsUnit.hvelocityDecayLimit
This float value is used to determine whether the object modeled by the physics system has come to rest due to deceleration.
@property (nonatomic, assign) CGFloat velocityDecayLimitDiscussion
@remarks The way PMTweenPhysicsSystem applies friction means that as velocity approaches 0, it will be assigned smaller and smaller fractional numbers, so we need a reasonable cutoff that approximates the velocity coming to rest. The default value is the internal constant PMTWEEN_DECAY_LIMIT (set to 1.0), which is fine for display properties, but you may prefer other values.
Declared In
PMTweenPhysicsUnit.hInstance Methods
initWithObject:propertyKeyPath:startingValue:velocity:friction:options:
Initalizes a new PMTweenPhysicsUnit object, passing in a target object, its property, and values for the tween operation.
- (instancetype)initWithObject:(NSObject *)object propertyKeyPath:(NSString *)propertyKeyPath startingValue:(double)startingValue velocity:(double)velocity friction:(double)friction options:(PMTweenOptions)optionsParameters
- object
- An object whose property should be tweened. 
- propertyKeyPath
- A string keyPath that points to a NSValue property of the target object to be tweened. Supported properties include several NSValue-encoded structs such as NSNumber, CGPoint, CGSize, CGRect, CGAffineTransform, and CATransform3D. 
- startingValue
- The property’s starting value for the tween operation. 
- velocity
- The velocity value to use in the physics calculations, measured in units per second. 
- friction
- The friction value between 0 and 1 to use in the physics calculations, with 1 representing very high friction and 0 representing almost no friction. 
- options
- A bitmask of - PMTweenOptionsconfiguration values. Defaults to- PMTweenOptionNone.
Return Value
A new instance of this class.
@remarks If you need to update the property of an object such as a UIView, use this method. PMTweenPhysicsUnit will handle updating the object’s property automatically if you have provided a valid keyPath to the property. For a keyPath to be valid, all objects or NSValue types must be supported. By supplying a custom class to structValueUpdater, you can handle structs that PMTweenPhysicsUnit doesn’t support by default.
See Also
- initWithProperty:startingValue:endingValue:duration:options:easingBlock:, @property structValueUpdater 
Declared In
PMTweenPhysicsUnit.hinitWithProperty:startingValue:velocity:friction:options:
Initializes a new PMTweenPhysicsUnit object, passing in a property and values for the tween operation.
- (instancetype)initWithProperty:(NSValue *)property startingValue:(double)startingValue velocity:(double)velocity friction:(double)friction options:(PMTweenOptions)optionsParameters
- property
- An NSValue property to be tweened. Supported properties include several NSValue-encoded structs such as NSNumber, CGPoint, CGSize, CGRect, CGAffineTransform, and CATransform3D. 
- startingValue
- The property’s starting value for the tween operation. 
- velocity
- The velocity value to use in the physics calculations, measured in units per second. 
- friction
- The friction value between 0 and 1 to use in the physics calculations, with 1 representing very high friction and 0 representing almost no friction. 
- options
- A bitmask of - PMTweenOptionsconfiguration values. Defaults to- PMTweenOptionNone.
Return Value
A new instance of this class.
@remarks If you need to tween an NSValue directly, without needing to update an object such as a UIView instance, using this method is adequate.
Declared In
PMTweenPhysicsUnit.hisReversing
A Boolean which determines whether a tween operation, when it has tweened to the ending value, should tween from the ending value back to the starting value.
- (BOOL)isReversingDiscussion
@remarks When set to YES, the tween plays in reverse after completing a forward tween. In this state, a tween cycle represents the combination of the forward and back tweens. The default value is NO.
Declared In
PMTweening.hpauseTween
Pauses a tween that is currently tweening. (required)
- (void)pauseTweenDiscussion
@remarks When this method is called, a tween should only enter a paused state if it is currently tweening.
Declared In
PMTweening.hresumeTween
Resumes a tween that is currently paused. (required)
- (void)resumeTweenDiscussion
@remarks When this method is called, a tween should only resume tweening if it is currently paused.
Declared In
PMTweening.hsetReversing:
A Boolean which determines whether a tween operation, when it has tweened to the ending value, should tween from the ending value back to the starting value.
- (void)setReversing:(BOOL)reversingDiscussion
@remarks When set to YES, the tween plays in reverse after completing a forward tween. In this state, a tween cycle represents the combination of the forward and back tweens. The default value is NO.
Declared In
PMTweening.hsetTempo:
A concrete PMTweenTempo subclass that provides an update “beat” while a tween operation occurs.
- (void)setTempo:(PMTweenTempo *)tempoDiscussion
@remarks While you don’t have to implement PMTweenTempo for your own class updating, other tween collection classes like PMTweenGroup will try to remove any tempos of tween objects added to them.
Declared In
PMTweening.hstartTween
Starts a tween that is currently stopped. (required)
- (void)startTweenDiscussion
@remarks When this method is called, a tween should only start tweening if it is stopped.
Declared In
PMTweening.hstopTween
Stops a tween that is currently tweening. (required)
- (void)stopTweenDiscussion
@remarks When this method is called, a tween should only enter a stopped state if it currently tweening.
Declared In
PMTweening.htempo
A concrete PMTweenTempo subclass that provides an update “beat” while a tween operation occurs.
- (PMTweenTempo *)tempoDiscussion
@remarks While you don’t have to implement PMTweenTempo for your own class updating, other tween collection classes like PMTweenGroup will try to remove any tempos of tween objects added to them.
Declared In
PMTweening.htempoBeatWithTimestamp:
Sends an update beat that should prompt tweening classes to recalculate tween values.
- (void)tempoBeatWithTimestamp:(NSTimeInterval)timestampParameters
- timestamp
- A timestamp with the current time, by which tween classes can calculate new tween values. 
Declared In
PMTweenTempo.h