XcodeLearningUIView AnimationExamples and practices are the content to be introduced in this article.UIView AnimationExamples and practicesXcodeTo learn and understandXcodeFirst, let's take a look at the details.
Here is an example of the fade-in and fade-out effect. The object relationship diagram is as follows:
- SampleAppDelegate
- HelloController init
- ToggleView init
- UIImageView init
- self addSubview
- UIImageView release
- ToggleView release
Release other objects
When a fade-in or fade-out event is triggered in the touchesBegan event of ToggleView, the animation of ToggleView itself is implemented to control the fade-out effect of UIImageView on the Child view, the UIImageView as a subview does not allow the exchange of touch imgView. userInteractionEnabled = NO;), only controls the display status.
Now I want to learn the new method of UIView. The following shows how to implement the fade-in and fade-out effect;
- // Perform the fade out or fade in
- CGContextRef context = UIGraphicsGetCurrentContext ();
- [UIView beginAnimations: nil context: context];
- [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration: 1.0];
- [[Self viewWithTag: IMAGE_VIEW_TAG] setAlpha :( float) isVisible]; // Note: This sets the display attribute for the current subview.
- [UIView commitAnimations];
UIView class
Class Method: animation part)
- beginAnimations:context:
-
- + (void)beginAnimations:(NSString *)animationID context:(void *)context
-
- Marks the beginning of a begin/commit animation block.
-
- setAnimationCurve:
-
- + (void)setAnimationCurve:(UIViewAnimationCurve)curve
-
- Sets the curve to use when animating property changes within an animation block.
-
- setAnimationDuration:
-
- + (void)setAnimationDuration:(NSTimeInterval)duration
-
- Sets the duration (measured in seconds) of the animations in an animation block.
-
- commitAnimations
-
- + (void)commitAnimations
-
- Marks the end of a begin/commit animation block and schedules the animations for execution.
Constants/Constant
- UIViewAnimationCurveEaseInOut
-
- An option for specifying an ease-in ease-out timing curve for the animation. An ease-in ease-out curve causes the animation to begin slowly,
- accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations.
-
- UIViewAnimationCurveEaseIn
-
- An option for specifying an ease-in timing curve for the animation. An ease-in curve causes the animation to begin slowly,
- and then speed up as it progresses.
-
- UIViewAnimationCurveEaseOut
-
- An option for specifying an ease-out timing curve for the animation. An ease-out curve causes the animation to begin quickly,
- and then slow down as it finishes.
-
- UIViewAnimationCurveLinear
-
- An option for specifying a linear timing curve for the animation. A linear animation curve causes an animation to occur evenly over its duration.
Summary:XcodeLearningUIView AnimationI hope this article will help you!