日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS之动画

發布時間:2024/8/26 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS之动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這幾天做項目,涉及到美觀和趣味性的問題,所以用到了動畫,但是現在的iOS動畫資料比較少,所以我自己整理了一些自己曾經用過的動畫例子來和大家分享,同時也歡迎有好的想法大家一起交流~~

序列幀動畫

曾經項目里的一段源碼:

UIImageView * activityImageView = [[UIImageView alloc] init]; NSMutableArray *imagesList = [NSMutableArray array]; for (NSInteger i = 1; i < 3; i++) {NSString *fileName = [NSString stringWithFormat:@"eggplant%i.png",i]; UIImage *image = [UIImage imageNamed:fileName]; [imagesList addObject:image]; } [activityImageView setAnimationImages:imagesList]; [activityImageView setAnimationDuration:0.5]; //0為無限循環 [activityImageView setAnimationRepeatCount:0]; [activityImageView startAnimating]; // [activityImageView stopAnimating];

UIView 動畫

UIViewAnimation

//創建一個CGAffineTransform transform對象 CGAffineTransform transform; //設置旋轉度數 transform = CGAffineTransformRotate(testView.transform,M_PI/6.0); //動畫開始 [UIView beginAnimations:@"rotate" context:nil ]; //動畫時常 [UIView setAnimationDuration:2]; //自動反轉 // [UIView setAnimationRepeatAutoreverses:YES]; [UIView setAnimationRepeatCount:3]; //添加代理 [UIView setAnimationDelegate:self]; //獲取transform的值 [testView setTransform:transform]; //關閉動畫 [UIView commitAnimations];

UIViewAnimationWithBlocks

/* Duration 動畫持續時間 delay 動畫延遲時間 options 動畫的節奏控制 */[UIView animateWithDuration:5 delay:5 options:UIViewAnimationOptionCurveEaseInOut animations:^{ testView.frame = CGRectMake(100, 300, 100, 100); } completion:^(BOOL finished) {}];/* Damping 動畫的彈力指數 Velocity 彈力的初速度 */[UIView animateWithDuration:0.5 delay:1 usingSpringWithDamping:0.8 initialSpringVelocity:10 options:0 animations:^{ testView.frame = CGRectMake(100, 300, 100, 100); } completion:^(BOOL finished) {}];

CoreAnimation

CATransition

繼承關系:CATransition -> CAAnimation

CATransition *transition = [CATransition animation]; transition.duration = 0.5; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; //動畫類型 transition.type = kCATransitionPush; //動畫方向 transition.subtype = kCATransitionFromTop; [testView.layer addAnimation:transition forKey:nil];

CAPropertyAnimation

繼承關系:CABasicAnimation,CAKeyframeAnimation -> CAPropertyAnimation -> CAAnimation

CABasicAnimation

CABasicAnimation * animation = [CABasicAnimation animation]; animation.keyPath = @"position.y";//運動的絕對距離 animation.fromValue = @77; animation.toValue = @455;//運動的相對距離 // animation.byValue = @222; animation.duration = 1; //留在最終狀態 animation.fillMode = @"forwards"; //防止它被自動移除 animation.removedOnCompletion = NO; animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.5 :0 :0.9 :0.7]; [testView.layer addAnimation:animation forKey:@"basic"];

CAKeyframeAnimation 例一

CAKeyframeAnimation * animation = [CAKeyframeAnimation animation]; animation.keyPath = @"position.x"; animation.values = @[@0,@10,@-10,@10,@0]; //指定關鍵幀動畫發生的時間 animation.keyTimes = @[ @0, @(1 / 6.0), @(3 / 6.0), @(5 / 6.0), @1 ]; animation.duration = 0.4; //提前無需設置位置 animation.additive = YES; [testView.layer addAnimation:animation forKey:@"shake"];

CAKeyframeAnimation 例二

CGRect boundingRect = CGRectMake(-150, -150,300, 300);CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation]; orbit.keyPath = @"position"; //創建一個圓形的 CGPath 作為我們的關鍵幀動畫的 path。 orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL)); orbit.duration = 2; orbit.additive = YES; orbit.repeatCount = HUGE_VALF; //恒定速度 orbit.calculationMode = kCAAnimationPaced; //確保沿著路徑旋轉 orbit.rotationMode = kCAAnimationRotateAuto; [testView.layer addAnimation:orbit forKey:@"orbit"];

CAAnimationGroup 組動畫

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; animation.duration = 3.; animation.fromValue = @(0.1); animation.toValue = @(1.);CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"]; animation2.duration = 3.; animation2.fromValue = @(1); animation2.toValue = @(2.); animation2.beginTime = 3.;CAAnimationGroup *group = [CAAnimationGroup animation]; group.duration = 6.; group.animations = @[animation,animation2]; [testView.layer addAnimation:group forKey:nil];

先就總結這么多,歡迎大家來補充。以后遇到更好也會寫出來和大家分享

轉載于:https://www.cnblogs.com/LeoTai/p/5493852.html

總結

以上是生活随笔為你收集整理的iOS之动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。