iOS-Senior17-UIView动画

一.UIView的基础动画

(代码版容易理解)

1.改变view的frame

@property (nonatomic,strong) UIView *textView;  (可以通过xib进行拖控件实现属性)

//UIView动画有开始beginAnimation,有结束commitAnimation

//第一步 : 开始UIView动画

[UIView beginAnimations : @"move" context : nil];

//第二步 : 设置动画的时长

[UIView setAnimationDuration : 3];

//第三步 : 设置UIView动画的回调代理

[UIView setAnimationDelegate : self];

//第四步 : 设置相关的对象的frame

self.textView.frame = CGRectMake (100,100,300,200);

//第五步 : 结束动画(提交动画)

[UIView commitAnimations];

 

2.改变view的backColor

//第一步 : 开始UIView动画

[UIView beginAnimations : @"color" context : nil];

//第二步 : 设置动画时长

[UIView setAnimationDuration : 0.3];

//第三步 : 设置回调代理

[UIView setAnimationDelegate : self];

//第四步 : 设置要改变的背景颜色

self.textView.backgroundColor = [UIColor yellowColor];

//第五步 : 结束动画

[UIView commitAnimations];

 

3.改变view的alpha

//第一步 : 开始UIView动画

[UIView beginAnimations : @"alpha" context : nil];

//第二步 : 设置时长

[UIView setAnimationsDuration : 0.4];

//第三步 : 设置回调代理

[UIView setAnimationDelegate : self];

//第四步 : 设置要改变的透明度

self.textView.alpha = 0.2;

//第五步 : 结束动画

[UIView commitAnimations];

 

4.仿射----翻转效果

//第一步 : 开始动画

[UIView beginAnimations : @"rotation" context : nil];

//第二步 : 设置动画时长

[UIView setAnimationDuration : 4];

//第三步 : 设置淡入的效果

[UIView setAnimationCurve : UIViewAnimationCurveEaseInOut];

//第四步 : 设置回调代理

[UIView setAnimationDelegate : self];

//第五步 : 设置翻转方向

[UIView setAnimationTransition : UIViewAnimationTransitionFilpFromLeft forView : self.textView cache : YES];

//第六步 : 提交动画

[UIView commitAnimations];

 

4.仿射----旋转效果

//第一步 : 开始动画

[UIView beginAnimations : @"transform" context : nil];

//第二步 : 设置时长

[UIView setAnimationDuration : 3];

//第三步 : 设置回调代理

[UIView setAnimationDelegate : self];

//第四步 : 设置旋转角度

CGAffine Transform transform = CGAffine TransformMakeRotation(3 * M_PI);

//第五步 : 设置旋转角度的对象

[self.textView setTransform : transform];

//第六步 : 结束动画

[UIView commitAnimations];

 

二.UIView的block调用

@property (nonatomic,strong) UIImageView *myImageView;

1.简单动画的实现方法

//第一个参数 : 设置动画时长

//第二个参数 : 动画要显示的效果

//第三个参数 : 动画完成时进行的事情

__weak typeof(self)weakSelf = self;

[UIView animationWithDuraton : 2.0f animations : ^{

//改变imageview的center位置

weakSelf.myImageView.center = self.view.center;

}completion : ^(BOOL finished) {

NSLog (@"海哥的位置变了");

}]; 

}

2.复杂动画的实现方法

//参数1 : 动画时长 参数2 : 动画延迟时间 参数3:动画的枚举值 参数4:要实现的动画效果 参数5:动画完成的时候要干的事情

__weak typeof(self)weakSelf = self;

[UIView animationWithDuration :5.0f delay : 1.0f options : UIViewAnimationOptionTransitionCulUp animations :^{

weakSelf.myImageView.frame = CGRectMake(10,100,100,100);

}completion :^(BOOL finished) {

NSLog(@"sea");

}];

3.关键帧动画的实现方法

//参数1:时长 参数2:延迟时间 参数3:枚举值 参数4:开始动画 参数5: 动画完成时的时候要干的事情

__weak typeof(self)weakSelf = self;

[UIView animateKeyframesWithDuration:2.0f delay:3.0f options:UIViewKeyframeAnimationOptionLayoutSubviews animations:^{

//在这里需要添加一个方法,即创建block的关键帧

//第一个参数:帧动画的开始时间

//第二个参数:帧动画的持续时间

[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{

//在这个里边写要实现的东西

weakSelf.myImageView.center = weakSelf.view.center;

}];

} completion:^(BOOL finished) {

NSLog(@"sea change");

}];

 

三.UIView的Spring动画

@property (nonatomic,strong) UIImageView springImage;

//参数1:动画时长

//参数2:延迟时间

//参数3:类似弹簧的效果值0-1

//参数4:初始化spring的一个速度

//参数5:spring动画的枚举值

//参数6:开始动画

//参数7:动画完成

__weak typeof(self)weakSelf = self;

[UIView animateWithDuration:3.0f delay:0.1f usingSpringWithDamping:1.0 initialSpringVelocity:10 options:UIViewAnimationOptionBeginFromCurrentState animations:^{

weakSelf.springImage.center = weakSelf.view.center;

} completion:^(BOOL finished) {

NSLog(@"mbboy");

 }];

 

 

posted on 2016-05-26 22:15  萌萌的周丽娜  阅读(155)  评论(0编辑  收藏  举报