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 }