同时对view延时执行两个动画时候的现象

同时对view延时执行两个动画时候的现象-LMLPHP

对于view延时执行了两个动画后,会将第一个动画效果终止了,直接在第一个动画的view的最后的状态上接执行后续的动画效果,也就是说,我们可以利用这个特性来写分段动画效果,比如,可以定时2秒,2秒的状态值为100%,中途可以停止,达不到2秒的效果就触发不了最终效果,这对于写控件来说是很好的一个属性哦,下次教程将会写一个按钮的特效的控件,效果类似于:

同时对view延时执行两个动画时候的现象-LMLPHP

效果:

同时对view延时执行两个动画时候的现象-LMLPHP

源码:

//
// ViewController.m
// ViewAnimation
//
// Created by YouXianMing on 15/1/13.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIView *showView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 添加view
self.showView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
self.showView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.showView]; // 1s后执行变长动画
[self performSelector:@selector(viewAnimationOne) withObject:nil afterDelay:]; // 2s后执行缩小动画
[self performSelector:@selector(viewAnimationTwo) withObject:nil afterDelay:];
} - (void)viewAnimationOne { // 动画时间长度为3s
[UIView animateWithDuration:.f animations:^{
self.showView.frame = CGRectMake(, , + , );
} completion:^(BOOL finished) {
NSLog(@"动画1结束 %@", NSStringFromCGRect(self.showView.frame));
}]; } - (void)viewAnimationTwo { // 动画时间长度为1s
[UIView animateWithDuration:.f animations:^{
self.showView.frame = CGRectMake(, , , );
} completion:^(BOOL finished) {
NSLog(@"动画2结束 %@", NSStringFromCGRect(self.showView.frame));
}];
} @end

同时对view延时执行两个动画时候的现象-LMLPHP

04-18 13:40