Physics for UIKit.
“Visual layers and realistic motion impart vitality and heighten users’ delight and understanding”
Buttons used to look like buttons, now they don’t. Don’t have visual cues. Compensate using Dynamics to add some motion.
Not for flappy birds. Has tried it, can get most of the way there. But there are fundamental missing parts. This is the road to disaster. Not what it is designed for, there are better frameworks out there.
How it works:
- Physics without having to understand all the hard stuff.
- UIDynamicItem (e.g. a view): a thing you can animate around the screen.
- UIDynamicBehavior (e.g. gravity): things that can happen to those things.
- UIDynamicAnimator: ties those together, responsible for running those animations.
- Just a protocol.
- Implemented by UIView.
- Defines 3 animatable properties:
- Responsible for applying behaviours to items.
- Defines a reference view, whose coordinate system is used for animations.
- Manages animations.
- Pauses when animations end.
- Use in a ViewController. Should be a property in a VC. Use VC’s own view as the reference view.
- Models a real world physical behaviour.
Built in behaviours:
- Attachement behaviour:
- Connects two views together.
- Move one view and another moves with it.
- Can use an anchor point rather than a second view.
- Can be springy (see damping, frequency properties).
- Models gravity.
- Add to an item and it falls downwards.
- You can optionally configure magnitude and angle.
- Models a force being applied to an item.
- Instantaneous (a kick) or continuous (a rocket engine).
- Snap a view back into place.
- Imagine held in place by four springs.
- Set damping to control how bouncy it is.
- Just another dynamic behaviour.
- Used to tell the animator about the state of dynamic items.
- Like a meta behaviour.
- Add additional properties:
- Linear velocity
Animators pause when nothing left to animate. what happens when it goes outside bounds?
Actually view continues accelerating as it falls down towards the centre of the earth.
This is bad because UIViews are flammable. If carried on unchecked, the earth explodes. Which is bad because kittens will die.
Stopping the animation:
- All dynamic behaviours have an action block.
- Gets executed for every frame
- Determine if out of view, if so remove from frame.
Basics. This is it, no hidden complicated stuff.
- New in iOS 7
- Give real physical properties with little code
- Create animator
- Create behaviour
- Delight and inform
- Try and use with auto layout.
- Try and recreate angry birds.