IOS开发 动画

UIVIEW基础动画

//标记动画块开始
[UIView beginAnimations:nil context:nil];
//定义动画加速和减速⽅方式
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//以秒为单位指定动画时⻓长
[UIView setAnimationDuration:0.5];
//设置代理
[UIView setAnimationDelegate:self];
//动画结束后回调⽅方法
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; /*视图变化动作在这⾥里*/
//标志动画块的结束
[UIView commitAnimations];

ALPHA变换(淡进/淡出)

//淡入过程
aView.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationDelegate:self];
aView.alpha = 1.0; [UIView commitAnimations];
//淡出过程
aView.alpha = 1.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationDelegate:self];
aView.alpha = 0.0; [UIView commitAnimations];

位置变换(位移)

aView.frame = CGRectMake(20, 20, 50, 50);
//x轴向右移动200位移
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:
1]; [UIView setAnimationDelegate:self]; aView.frame = CGRectMake(220, 20, 50, 50); [UIView commitAnimations];

缩放变换

CGAffineTransform transform = myView.transform;
//缩⼩小尺⼨寸
myView.transform = CGAffineTransformScale(transform, 0.01, 0.01);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
//还原为原来的尺⼨寸
myView.transform = CGAffineTransformScale(transform, 1, 1);
myView.transform = CGAffineTransformIdentity;
[UIView commitAnimations];

旋转变换

//旋转90度
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:
1]; [UIView setAnimationDelegate:self]; view.transform = CGAffineTransformMakeRotation(3.14/2.0); [UIView commitAnimations];

视图切换的过渡动画

UIViewAnimationTransitionFlipFromLeft

从左向右翻转,用新视图代替旧视图

UIViewAnimationTransitionFlipFromRigh

从右向左做翻转,隐藏旧视图,显示新视图

UIViewAnimationTransitionCurlUp

用从下向上翻页的方式显示新视图

UIViewAnimationTransitionCurlDown

新视图从上向下翻页盖住旧视图

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.6];
//为parentView添加动画效果
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES];
//在parentView执⾏行动画的时候,调换两个视图的位置,以达到视图切换的效果
[parentView exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2];
[UIView commitAnimations];

BLOCK语法动画

// 1.淡⼊入动画
[UIView animateWithDuration:0.5 animations:^(void){ //动画开始执⾏行调⽤用的 block
    self.myView.alpha = 1.0;
} completion:^(BOOL finish) { //动画结束调⽤用的block
    NSLog(@"动画结束");
}];

// 2.视图切换
UIViewAnimationOptions options = UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut;
[UIView transitionWithView:parentView duration:3.0f options:options animations:^{
    [parentView exchangeSubviewAtIndex:page1Index withSubviewAtIndex:page2Index];
} completion:^(BOOL finished) {
    NSLog(@"finished %d", finished);
}];

主要方法

// 设置代理缺省为nil
+ (void)setAnimationDelegate:(id)delegate;
// 设置动画开始的调⽤用⽅方法,缺省NULL.
+ (void)setAnimationWillStartSelector:(SEL)selector;
// 设置动画停⽌止的调⽤用⽅方法,缺省NULL
+ (void)setAnimationDidStopSelector:(SEL)selector;
// 设置动画持续事件,缺省是0.2秒
+ (void)setAnimationDuration:(NSTimeInterval)duration;
// 设置动画的⽅方式,缺省是UIViewAnimationCurveEaseInOut
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;
// 设置动画的重复次数,缺省是0
+ (void)setAnimationRepeatCount:(float)repeatCount;

CATRANSITION动画

·CATransition是对UIView进行更低层次的控制。

·CATransition 不同于UIView动画,它是作用于UIView的Layer层

·CATransition 主要用于两个视图切换过渡时的动

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2014-10-17 15:03  rwpnyn  阅读(139)  评论(0编辑  收藏  举报

导航