国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOSCoreAnimation學習總結(3)--動畫的基本類型

2019-11-14 18:07:57
字體:
來源:轉載
供稿:網友

一. CABasicAnimation (基礎動畫)

移位:

    CABasicAnimation *animation = [CABasicAnimation animation];    //keyPath指定動畫類別,position表示移位    animation.keyPath = @"position";    //移動到x=200,y=200的位置    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];    animation.duration = 2;    //動畫執行完畢后不刪除動畫    animation.removedOnCompletion = NO;    //保持最新的狀態    animation.fillMode = @"forwards";    //添加動畫    [self.layer addAnimation:animation forKey:nil];

縮放:

    CABasicAnimation *animation = [CABasicAnimation animation];    //keyPath指定動畫類別,bounds表示縮放    animation.keyPath = @"bounds";    //縮放到width=50,height=50    animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];    animation.duration = 2;    //動畫完成不刪除動畫    animation.removedOnCompletion = NO;    //保持最新的狀態    animation.fillMode = @"forwards";        [self.layer addAnimation:animation forKey:nil];

旋轉:

    CABasicAnimation *animation = [CABasicAnimation animation];    //keyPath指定動畫類別,transform表示旋轉    animation.keyPath = @"transform";    //沿x,y軸順時針旋轉45度    animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 1, 1, 0)];    animation.duration = 2;    animation.removedOnCompletion = NO;    animation.fillMode = @"forwards";        [self.layer addAnimation:animation forKey:nil];

 

二.  CAKeyframeAnimation (關鍵幀動畫)

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];        anim.keyPath = @"position";    anim.removedOnCompletion = NO;    anim.fillMode = kCAFillModeForwards;    anim.duration = 2.0;        //設置圓形軌跡,并繞圓形軌跡移動    CGMutablePathRef path = CGPathCreateMutable();    CGPathAddEllipseInRect(path, NULL, CGRectMake(100, 100, 200, 200));    anim.path = path;    CGPathRelease(path);            // 設置動畫的執行節奏    // kCAMediaTimingFunctionEaseInEaSEOut : 一開始比較慢, 中間會加速,  臨近結束的時候, 會變慢    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];    anim.delegate = self;    [anim setValue:@"aaa" forKey:@"TAG"];    [self.layer addAnimation:anim forKey:nil];

設置代理的回調方法,讓動畫結束后彈出提示

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{    NSString *strTag = [anim valueForKey:@"TAG"];    if ([strTag isEqualToString:@"aaa"]) {        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Animation Done" message:@"動作完成" delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil];        [alert show];    }}

 

三. CATransition(轉場動畫)

(1)視圖跳轉

    _newView = [[UIView alloc] init];    _newView.frame = CGRectMake(100, 100, 100, 100);    [self.view addSubview:_newView];        UIView *view1 = [[UIView alloc] init];    view1.frame = CGRectMake(0, 0, 100, 100);    view1.backgroundColor = [UIColor yellowColor];    [_newView addSubview:view1];        UIView *view2 = [[UIView alloc] init];    view2.frame = CGRectMake(0, 0, 100, 100);    view2.backgroundColor = [UIColor greenColor];    [_newView addSubview:view2];

添加轉場按鈕事件處理:

- (IBAction)exchangeView {    // 轉場動畫    CATransition *transition = [CATransition animation];    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];    transition.type = @"pageCurl";    transition.subtype = kCATransitionFromRight;    transition.duration = 1;    [_newView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];    [_newView.layer addAnimation:transition forKey:@"myAnimation"];}

(2)控制器跳轉

- (IBAction)pushView {    CATransition *transition = [CATransition animation];    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];    //立體動畫效果    transition.type = @"cube";    [self.navigationController.view.layer addAnimation:transition forKey:@"navAnimation"];    TestViewController *testVC = [[TestViewController alloc] init];    [self.navigationController showViewController:testVC sender:nil];}

四. CAAnimationGroup (組合動畫)

    //添加圖片    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"curry.jpg"]];    imgView.frame = CGRectMake(100, 100, imgView.frame.size.width, imgView.frame.size.height);    [self.view addSubview:imgView];        //貝塞爾曲線路徑    UIBezierPath *movePath = [UIBezierPath bezierPath];    [movePath moveToPoint:CGPointMake(10.0, 10.0)];    [movePath addQuadCurveToPoint:CGPointMake(100, 300) controlPoint:CGPointMake(300, 100)];        //以下必須導入QuartzCore包    //關鍵幀動畫(位置)    CAKeyframeAnimation * posAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];    posAnim.path = movePath.CGPath;    posAnim.removedOnCompletion = YES;        //縮放動畫    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];    scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];    scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];    scaleAnim.removedOnCompletion = YES;        //透明動畫    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];    opacityAnim.toValue = [NSNumber numberWithFloat:0.1];    opacityAnim.removedOnCompletion = YES;        //動畫組    CAAnimationGroup *animGroup = [CAAnimationGroup animation];    animGroup.animations = [NSArray arrayWithObjects:posAnim, scaleAnim, opacityAnim, nil];    animGroup.duration = 1;        [imgView.layer addAnimation:animGroup forKey:nil];

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肃宁县| 临夏县| 怀来县| 察雅县| 五台县| 富裕县| 汾西县| 长葛市| 东乡县| 广汉市| 宁阳县| 南通市| 探索| 化隆| 合山市| 郎溪县| 慈溪市| 东台市| 德格县| 沙湾县| 潜山县| 武隆县| 泉州市| 武夷山市| 扎赉特旗| 扎鲁特旗| 常德市| 佛坪县| 绥滨县| 平和县| 灌云县| 甘泉县| 延津县| 额敏县| 驻马店市| 花莲县| 沂源县| 乳源| 伊金霍洛旗| 丹棱县| 海口市|