关于transform的一些用法

来源:互联网 发布:知乎女神芈十四 编辑:程序博客网 时间:2024/04/30 05:12

旋转  缩放  偏移  反转

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 }
复制代码

0 0