concept animation in category ios

appears as: nimation, nimations, An imation, imation, n animation, Animation, imations
Hello! iOS Development

This is an excerpt from Manning's book Hello! iOS Development.

A page-based application lets you build apps that look like books and have built-in page turning animation and navigation.

Using animation to make disguises grow

In chapter 5, you learned that animation on the iPhone is simple. Just start an animation, change properties, and then commit the app. All the actual animation of the in-between states is taken care of for you. The trickiest part is coming up with how to use animations in the first place.

iOS Development with Swift

This is an excerpt from Manning's book iOS Development with Swift.

The viewDidAppear method is called after the root view is displayed. This method is commonly overridden to initiate processor-intensive work that otherwise could cause sluggishness in presenting the view. This could include starting an animation, playing a sound, or making a network call.

Now that you’ve detected when the keyboard moves on, you want to move the text field up so the user can see where they’re editing. Rather than the interface jumping into place, animating it smoothly is a much better idea. Animation in an app can be the difference between a boring, static app and a slick, interesting, energetic experience. But animation isn’t only pretty; it can also be practical. You can use animation to indicate elements you want the user to interact with; you can animate elements the user interacts with to give the user the illusion of a more tactile experience; and you can animate elements to help illustrate instructions or results.

We’ve already explored adding animations to coordinators of scene transitions called transition coordinators. In chapter 6, you passed a closure to a transition coordinator object containing changes to properties of a view that you want to animate during a size change. You can also pass a closure of animations to the transition coordinator during transitions between trait collections (size classes), or transitions between scenes, called segues. We’ll come back to animation during segues in chapter 9.

You can also initiate a closure of animations by passing them into a type method on the UIView class called animate. You’ll use this method now to animate basic properties on a view.

Most properties that affect how a view appears can be passed into the closure of animations. These properties include those shown in table 8.1.

Table 8.1. Animatable properties

Type of animation

View properties

Size frame.size or bounds.size
Location frame.origin or center
Transparency alpha
Background color backgroundColor
Rotation, scale, skew, translate transform
  • Add the following to the touchViewButton method to trigger when the user taps the View button. Pass in the two required parameters of the animate method, withDuration and animations:
    self.bar1.frame.size.width = 0                            1
    self.bar2.frame.size.width = 0                            1
    UIView.animate(withDuration: 1,                           2
       animations: {                                          3
           self.bar1.backgroundColor = UIColor.red            3
           self.bar1.frame.size.width = 150                   3
           self.bar2.backgroundColor = UIColor.orange         3
           self.bar2.frame.size.width = 150                   3
       }                                                      3
    )
    • 1 Sets up prior to animation
    • 2 Initializes the property
    • 3 Closure of properties to animate
  • One solution is to update the layout’s constraints to represent its new layout after the animation is complete. In this case, as in the new layout, the two bars should be 150 points wide; you could pass 150 to the constants of the two width constraints.

    iPhone in Action: Introduction to Web and SDK Development

    This is an excerpt from Manning's book iPhone in Action: Introduction to Web and SDK Development.

  • You need to use any function (such as the address book, the accelerometers, the GPS, the camera, or animation) that isn’t well supported on the web
  • 6.9. Applying animation

    We’re going to start with a caveat: Canvas isn’t really intended for animation. You can do it (depending on the good graces of your user’s CPU), but unlike with Flash, animation is not a core purpose of the programming language. This means that whenever you do animation with Canvas, it’s going to be a lot awkward and a little kludgy—and thus, it’s generally something that you should use as spice in your graphical web app, and not as the main course.

    You’ll have to overcome two main obstacles when animating using Canvas. First, you have to deal with the fact that Canvas doesn’t have any animation methods. Worse, once things are drawn on the canvas, they stay on the canvas. That means that whenever you animate, you have to clear your canvas (using clearRect), draw your background, and draw your figure, and then clear your canvas, draw your background, and draw your somewhat changed or moved figure, and so on. You repeat this exercise throughout the animation.

    Second, you should note that whenever you’re writing to the canvas with a function, nothing gets written to the canvas until the function is completed. Thus, you can’t use anything obvious like a for loop to do an animation. Instead, you have to draw, end your function, then later call it again with setInterval, setTimeout, or an event handler.