麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

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];

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大西瓜永久免费av在线 | 久草在线资源福利站 | 欧美性精品videofree | 色呦呦一区二区三区 | 一级做a爱性色毛片免费1 | 黄色小视频在线免费看 | 日本视频网 | 久久久久国产成人免费精品免费 | 黄色片视频观看 | 高清一区二区在线观看 | 欧美成人一区免费视频 | 欧美hdfree性xxxx| wwwxxx免费视频 | 超碰97最新| 麻豆国产网站 | 成人毛片视频在线观看 | 九九热在线观看视频 | 午夜视频你懂的 | 女人一级一级毛片 | 手机免费看一级片 | 国产精品久久久久久久久久大牛 | 黄色av网站在线观看 | 国产精品一区99 | 精品99在线视频 | 国产精品久久久久久久久久三级 | 亚洲免费视频一区二区 | 久久久久女人精品毛片九一 | 精品国产一区二区三区四区阿崩 | 久久精品视频网址 | 久久精品99久久久久久2456 | 精品一区二区三区网站 | 黄污网址| 午夜视频观看 | 国产亚洲精彩视频 | 91成人久久 | 在线91视频 | 黄在线观看 | 91成人免费网站 | av电影网站在线 | 操你啦免费视频 | 亚洲日本韩国在线观看 |