UIKit Animation

 

UIKit Animation


1.属性动画

- (void)changeFrameAnimation {
[UIView beginAnimations:@"frameAnimation" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationDelegate:self];
[UIView setAnimationWillStartSelector:@selector(startAnimation:)];
[UIView setAnimationDidStopSelector:@selector(stopAnimation:)];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationRepeatCount:1];

// [UIView setAnimationRepeatAutoreverses:YES];

self.secondView.frame = self.firstView.frame;

[UIView commitAnimations];
}

2.Transition 提供了一个图层变化的过渡效果,它能影响图层的整个内容

- (void)transitionAnimation {
[UIView beginAnimations:@"frameAnimation" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationDelegate:self];
[UIView setAnimationWillStartSelector:@selector(startAnimation:)];
[UIView setAnimationDidStopSelector:@selector(stopAnimation:)];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];

[UIView setAnimationRepeatCount:1];

self.firstView.backgroundColor = [UIColor purpleColor];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.firstView cache:YES]; // 转场效果,forView 动画作用对象

[UIView commitAnimations];
}
  1. Block Animation
- (void)block1 {
[UIView animateWithDuration:0.8 animations:^{
self.secondView.frame = self.firstView.frame;
}];
}

- (void)block2 {
[UIView animateWithDuration:0.8 animations:^{
self.secondView.frame = self.firstView.frame;
} completion:^(BOOL finished) {
NSLog(@"complete blockAnimation");
}];
}

- (void)block3 {
[UIView animateWithDuration:0.8 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.secondView.frame = self.firstView.frame;
} completion:^(BOOL finished) {
NSLog(@"options");
}];
}

4.SpringAnimation

/**
* @author Jack Lee, 16-05-16 15:05:05
*
* @brief after iOS7.0
*/

- (void)springAnimation {
// damping:取值范围0~1,值越小振荡越明显
// velocity:初始速度,越大越快
[UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
self.secondView.frame = self.firstView.frame;
} completion:^(BOOL finished) {
NSLog(@"complete spring");
}];
}

5.关键帧动画

/**
* @author Jack Lee, 16-05-16 15:05:00
*
* @brief after iOS7.0
*/

- (void)keyFrameAnimation {
[UIView animateKeyframesWithDuration:4 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1 animations:^{
self.firstView.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
}];

[UIView addKeyframeWithRelativeStartTime:1 relativeDuration:1 animations:^{
self.firstView.backgroundColor = [UIColor colorWithRed:0.8 green:0.6 blue:0.6 alpha:1];
}];

[UIView addKeyframeWithRelativeStartTime:2 relativeDuration:1 animations:^{
self.firstView.backgroundColor = [UIColor colorWithRed:0.8 green:0.4 blue:0.4 alpha:1];
}];

[UIView addKeyframeWithRelativeStartTime:3 relativeDuration:1 animations:^{
self.firstView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1];
}];

} completion:^(BOOL finished) {
NSLog(@"complete keyframe animation");
}];
}
  1. Transition过渡动画二
- (void)block3 {
[UIView transitionWithView:self.firstView duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
self.firstView.backgroundColor = [UIColor colorWithRed:0.2 green:0.5 blue:0.7 alpha:1];
} completion:^(BOOL finished) {
NSLog(@"complete block3");
}];
}

- (void)block4 {
UILabel *l = [[UILabel alloc] initWithFrame:self.firstView.frame];
l.font = [UIFont systemFontOfSize:30];
l.textColor = [UIColor orangeColor];
l.textAlignment = NSTextAlignmentCenter;
l.text = @"翻转";

[UIView transitionFromView:self.firstView toView:l duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
NSLog(@"from to complete");
}];

}
 

转载于:https://www.cnblogs.com/buakaw/p/5725674.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值