The following sections focus on the code you need in order to animate changes to view properties. However, the block-based methods are preferred whenever possible. Both techniques support the same configuration options and offer the same amount of control over the animation execution. In earlier versions of iOS, you mark the beginning and end of an animation block using special class methods of the UIView class. In iOS 4 and later, you create an animation block using block objects. The term animation block is used in the generic sense to refer to any code that designates animatable changes. In order to animate changes to a property of the UIView class, you must wrap those changes inside an animation block. For more complete information about how to use Core Animation to animate layers, see Core Animation Programming Guide and Core Animation Cookbook. Note: If your view hosts custom layer objects-that is, layer objects without an associated view-you must use Core Animation to animate any changes to them.Īlthough this chapter addresses a few Core Animation behaviors, it does so in relation to initiating them from your view code. The clipping behavior for sublayers that lie outside the layer’s bounds The portion of the layer that stretches during resizing operations The layer’s border (including whether the layer’s corners are rounded) The layer’s Z-order relative to other sibling layers The addition or removal of a layer from the layer hierarchy Transformations to the layer or its sublayers in 3D space The center point used when performing transformations Using Core Animation, you can animate the following types of changes for your view’s layer: Because view and layer objects are intricately linked together, changes to a view’s layer affect the view itself. In places where you want to perform more sophisticated animations, or animations not supported by the UIView class, you can use Core Animation and the view’s underlying layer to create the animation. In those situations, you can use view-based transitions to animate the addition and removal of your views. Although you should use view controllers to manage succinct view hierarchies, there may be times when you want to replace all or part of a view hierarchy. Modify this property to change the way the view’s contents are stretched to fill the available space.Īnimated view transitions are a way for you to make changes to your view hierarchy beyond those offered by view controllers. Modify this property to change the view’s background color. Modify this property to gradually change the transparency of the view. (To perform 3D transformations, you must animate the view’s layer object using Core Animation.) Transformations using this property are always performed in 2D space. Modify this property to scale, rotate, or translate the view relative to its center point. Modify this property to change the view’s position relative to its superview’s coordinate system. Modify this property to change the view’s size. (If the transform property does not contain the identity transform, modify the bounds or center properties instead.) Modify this property to change the view’s size and position relative to its superview’s coordinate system. To animate such a change, you must change the property’s value from inside an animation block, which is described in Animating Property Changes in a View. Changing the value of these properties normally just updates the property (and the view) immediately without an animation. Being animatable does not mean animations happen automatically. Table 4-1 lists the animatable properties-the properties that have built-in animation support-of the UIView class. For example, you can animate changes to properties of views or use transition animations to replace one set of views with another. Views support a basic set of animations that cover many common tasks. In UIKit, animations are performed using UIView objects. What Can Be Animated?īoth UIKit and Core Animation provide support for animations, but the level of support provided by each technology varies. This makes creating sophisticated animations very easy with only a few lines of code. All you have to do is trigger the animation and let Core Animation handle the rendering of individual frames. All of the animation techniques described in this chapter use the built-in support provided by Core Animation. In iOS, creating sophisticated animations does not require you to write any drawing code. You might use animations to convey feedback to the user or to implement interesting visual effects. In iOS, animations are used extensively to reposition views, change their size, remove them from view hierarchies, and hide them. Animations provide fluid visual transitions between different states of your user interface.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |