缩放动画
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
{
//让动画执行
self.tipLab.layer.speed=1;
//取消上次设置的时间
self.tipLab.layer.beginTime = 0;
//获取上次动画停留的时刻
CFTimeInterval pauseTime = self.tipLab.layer.timeOffset;
//取消上次记录的停留时刻
self.tipLab.layer.timeOffset = 0;
//计算暂停的时间,设置相对于父坐标系的开始时间
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;
}
}
网友评论