縮放動畫
UILabel *tipLab=[[UILabel alloc]initWithFrame:CGRectMake(0, 70, kScreenW, 40)];? ? ? ? ?tipLab.textColor=[UIColor whiteColor];
tipLab.text=@"xxxx";
[self.viewaddSubview:tipLab];
self.tipLab=tipLab;
?tipLab.transform = CGAffineTransformMakeScale(1.0, 0.2);
?[UIView animateWithDuration:0.8 animations:^{
? ? ? ? ? ? ? ? tipLab.transform = CGAffineTransformMakeScale(1.0, 1.0);
? ? }completion:^(BOOLfinish){
? ? ? ? ? ? ? ?CFTimeInterval pausedTime = [tipLab.layer convertTime:CACurrentMediaTime() fromLayer:nil];
? ? ? ? ? ? ? ?//將動畫暫停
? ? ? ? ? ? ? ?tipLab.layer.speed = 0;
? ? ? ? ? ? ? ? tipLab.layer.timeOffset = pausedTime;
? ? ? ? ? ? ? ? NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(updateTimer:) userInfo:nil repeats:NO];
? ? ? ? ? ? ? ? [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];
? ? ? ? ? ? }];
-(void)updateTimer:(NSTimer*)timer
{
? ? //讓動畫執(zhí)行
? ? self.tipLab.layer.speed=1;
? ? //取消上次設(shè)置的時(shí)間
? ? self.tipLab.layer.beginTime = 0;
? ? //獲取上次動畫停留的時(shí)刻
? ? CFTimeInterval pauseTime = self.tipLab.layer.timeOffset;
? ? //取消上次記錄的停留時(shí)刻
? ? self.tipLab.layer.timeOffset = 0;
? ? //計(jì)算暫停的時(shí)間蚪拦,設(shè)置相對于父坐標(biāo)系的開始時(shí)間
? ? self.tipLab.layer.beginTime = [self.tipLab.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pauseTime;
? ? [UIView animateWithDuration:0.8 animations:^{
? ? ? ? self.tipLab.transform = CGAffineTransformMakeScale(1.0, 1.0);
? ? }completion:^(BOOLfinish){
? ? ? ? [UIView animateWithDuration:0.8 animations:^{
? ? ? ? ? ? self.tipLab.transform = CGAffineTransformMakeScale(1.0, 0.2);
? ? ? ? }completion:^(BOOLfinish){
? ? ? ? ? ? self.tipLab.transform = CGAffineTransformMakeScale(1.0, 0.0);
? ? ? ? }];
? ? }];
}
高度從無到有再到無動畫
UILabel *tipLab=[[UILabel alloc]initWithFrame:CGRectMake(0, 70, kScreenW, 40)];? ? ? ? ?tipLab.textColor=[UIColor whiteColor];
tipLab.text=@"xxxx";
[self.viewaddSubview:tipLab];
self.tipLab.frame = CGRectMake(0, 70, kScreenW,0);
? ? ? ? ? ? [UIView animateWithDuration:0.8 animations:^{
? ? ? ? ? ? ? ? self.tipLab.frame=CGRectMake(0,70,kScreenW,40);
? ? ? ? ? ? }completion:^(BOOLfinish){
? ? ? ? ? ? ? ? NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(updateTimer:) userInfo:nil repeats:NO];
? ? ? ? ? ? ? ? [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];
? ? ? ? ? ? }];
-(void)updateTimer:(NSTimer*)timer
{
? ? [UIView animateWithDuration:0.8 animations:^{
? ? ? ? self.tipLab.frame=CGRectMake(0,70,kScreenW,0);
? ? }completion:^(BOOLfinish){
? ? ? ? [self removeTipLabel];
? ? }];
}
-(void)removeTipLabel
{
? ? if(self.tipLab) {
? ? ? ? [self.tipLab removeFromSuperview];
? ? ? ? self.tipLab=nil;
? ? ? ? [self.timerinvalidate];
? ? ? ? self.timer=nil;
? ? }
}