同时对view延时执行两个动画时候的现象
生活随笔
收集整理的這篇文章主要介紹了
同时对view延时执行两个动画时候的现象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
同時對view延時執行兩個動畫時候的現象
對于view延時執行了兩個動畫后,會將第一個動畫效果終止了,直接在第一個動畫的view的最后的狀態上接執行后續的動畫效果,也就是說,我們可以利用這個特性來寫分段動畫效果,比如,可以定時2秒,2秒的狀態值為100%,中途可以停止,達不到2秒的效果就觸發不了最終效果,這對于寫控件來說是很好的一個屬性哦,下次教程將會寫一個按鈕的特效的控件,效果類似于:
效果:
源碼:
// // 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];// 添加viewself.showView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 0, 30)];self.showView.backgroundColor = [UIColor redColor];[self.view addSubview:self.showView];// 1s后執行變長動畫[self performSelector:@selector(viewAnimationOne) withObject:nil afterDelay:1];// 2s后執行縮小動畫[self performSelector:@selector(viewAnimationTwo) withObject:nil afterDelay:2]; }- (void)viewAnimationOne {// 動畫時間長度為3s[UIView animateWithDuration:3.f animations:^{self.showView.frame = CGRectMake(10, 100, 0 + 300, 30);} completion:^(BOOL finished) {NSLog(@"動畫1結束 %@", NSStringFromCGRect(self.showView.frame));}];}- (void)viewAnimationTwo {// 動畫時間長度為1s[UIView animateWithDuration:1.f animations:^{self.showView.frame = CGRectMake(10, 100, 0, 30);} completion:^(BOOL finished) {NSLog(@"動畫2結束 %@", NSStringFromCGRect(self.showView.frame));}]; }@end?
總結
以上是生活随笔為你收集整理的同时对view延时执行两个动画时候的现象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cache命令小结
- 下一篇: 基本shell编程【3】- 常用的工具a