IOS学习笔记(三)UIView animation

iphone中动画的实现主要分为两种,UIView动画 和Core Animation动画

UIView动画主要可以实现的效果包括:

1.frame,bounds,center//改变View的frame属性

 1 -(void)doChangeFrame

 2 {

 3 //{

 4 //    [UIView beginAnimations:nil context:nil];

 5 //    [UIView setAnimationDuration:2];

 6 //    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

 7 //    [UIView setAnimationDelegate:self];

 8 //    [UIView setAnimationDidStopSelector:@selector(stopDelegate)];

 9 //    smallImage.frame = CGRectMake(150, 80, 30, 30);

10 //    

11 //    //smallImage.alpha = 0;

12 //    [UIView commitAnimations];

13     

14     [UIView animateWithDuration:2.0 animations:^(void){smallImage.frame = CGRectMake(150, 80, 30, 30);} completion:^(BOOL finished) {

15         smallImage.alpha = 0;

16     }];

17 //块语句定义及使用方法

18    /*int (^myBlock )(int num) = ^(int num)

19     {

20         return num*2;

21     };

22     NSLog(@"%d",myBlock(7));*/

23 }

 

2.alpha //改变透明度

3.backgroundColor //改变背景颜色

4.contentStretch //拉伸变化

5.transform //仿射变换,其中又包括Rotate,Invert,Translate,Scale(旋转,反转,位移,缩放)

1 -(void)doRotate//旋转

2 {

3     CGAffineTransform transform=         CGAffineTransformMakeRotation(M_PI/4);

4     

5     [UIView beginAnimations:nil context:nil];

6     bigImage.transform = transform;

7     [UIView commitAnimations];

8 }
 1 -(void)doInvert//反转

 2 {

 3     BOOL isSingle = seg.selectedSegmentIndex;

 4     //如果单次 直接翻转到原始状态 如果连续 在以前基础上再次进行反转

 5     

 6     CGAffineTransform transform = isSingle?CGAffineTransformInvert(bigImage.transform):CGAffineTransformIdentity;

 7     

 8     [UIView beginAnimations:nil context:nil];

 9     bigImage.transform = transform;

10     [UIView commitAnimations];

11 }
 1 -(void)doTranslate//位移

 2 {

 3     BOOL isSingle = seg.selectedSegmentIndex;

 4     //如果单次 只改变一次 如果连续 在以前基础上再次进行移位

 5     CGAffineTransform transform = isSingle?CGAffineTransformMakeTranslation(10, 10):CGAffineTransformTranslate(bigImage.transform, 10, 10);

 6     

 7 //    [UIView beginAnimations:nil context:nil];

 8 //    bigImage.transform = transform;

 9 //    [UIView commitAnimations];

10     [UIView animateWithDuration:1 animations:^{

11       bigImage.transform = transform;

12     }];

13 }
 1 -(void)doScale//缩放

 2 {

 3     BOOL isSingle = seg.selectedSegmentIndex;

 4     //如果单次 只改变一次 如果连续 在以前基础上再次进行缩放

 5     CGAffineTransform transform = isSingle?CGAffineTransformMakeScale(1.0, 1.1):CGAffineTransformScale(bigImage.transform, 1.0, 1.1);

 6     

 7     [UIView beginAnimations:nil context:nil];

 8     bigImage.transform = transform;

 9     [UIView commitAnimations];

10 

11 }

你可能感兴趣的:(animation)