码迷,mamicode.com
首页 > 移动开发 > 详细

IOS 动画

时间:2014-11-26 22:45:38      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   color   os   sp   for   on   art   

//uiview动画
    //开始动画
    [UIView beginAnimations:nil context:nil];
    
    //运动的时间
    [UIView setAnimationDuration:2.f];
    //延时启动
    [UIView setAnimationDelay:2];
    //速度曲线(可以改变速度)
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    //代理
    [UIView setAnimationDelegate:self];
    //代理方法 开始时候执行
    [UIView setAnimationWillStartSelector:@selector(start)];
    //结束时候执行
    [UIView setAnimationDidStopSelector:@selector(stop)];
    //重复执行
    [UIView setAnimationRepeatAutoreverses:YES];
    //重复几次
    [UIView setAnimationRepeatCount:2];
    //重复
    [UIView setAnimationsEnabled:YES];
    //翻转
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.Testview cache:YES];
    
    //动画过程
    self.Testview.backgroundColor = [UIColor colorWithRed:arc4random()%255/256.0 green:arc4random()%255/256.0 blue:arc4random()%255/256.0 alpha:1];
    //提交动画
    [UIView commitAnimations];
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);">//<span style="font-family: 'Heiti SC Light';">系统自带</span>block</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);">    [UIView animateWithDuration:2.f animations:^{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87); min-height: 21px;">        </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);">    }];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);"><pre name="code" class="objc">[UIView transitionWithView:self.view duration:2.f options:(UIViewAnimationOptionTransitionFlipFromTop) animations:^{
        NSLog(@"开始动画");
        self.MyView.backgroundColor = [UIColor greenColor];
    } completion:^(BOOL finished) {
        self.MyView.backgroundColor = [UIColor orangeColor];
        NSLog(@"动画结束");
    }];

[UIView animateWithDuration:2.f animations:^{
//        self.MyView.transform = CGAffineTransformTranslate(self.MyView.transform, 0.5f, 0.5f);
        self.MyView.transform = CGAffineTransformRotate(self.MyView.transform, M_PI_2);
        
    }];
<pre name="code" class="objc">//模拟自带block自己写的方法
-(void)myAnimationDuration:(NSTimeInterval)time
                 animation:(myBlock)ani
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:time];
    ani();
    [UIView commitAnimations];
}

//给view设置边缘 描边粗细
    self.myview.layer.borderWidth = 20;
    //描边颜色(注意类型转换)
    self.myview.layer.borderColor = [UIColor yellowColor].CGColor;
    //阴影偏移
    self.myview.layer.shadowOffset = CGSizeMake(50, 50);
    //阴影颜色
    self.myview.layer.shadowColor = [UIColor grayColor].CGColor;
    //阴影透明度
    self.myview.layer.shadowOpacity = 0.8;
    //模糊程度
    self.myview.layer.shadowRadius = 10

//第一种


<pre name="code" class="objc">CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.duration = 2.0;
    animation.repeatCount = 30;
    animation.autoreverses = YES;
    
    NSArray *array = @[[NSValue valueWithCGPoint:CGPointMake(25, 25)],[NSValue valueWithCGPoint:CGPointMake(200, 25)],[NSValue valueWithCGPoint:CGPointMake(25, 200)],[NSValue valueWithCGPoint:CGPointMake(200, 200)]];
    
    animation.values = array;
    [self.myview.layer addAnimation:animation forKey:@"asd"];

//第二种

<pre name="code" class="objc">CAAnimationGroup *group = [CAAnimationGroup animation];
    //1
    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    //初始值
    animation1.fromValue = [NSNumber numberWithFloat:0.3];
    //结束值
    animation1.toValue = [NSNumber numberWithFloat:3.0];
    //2
    CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation2.values = @[[NSValue valueWithCGPoint:CGPointMake(25, 25)],[NSValue valueWithCGPoint:CGPointMake(200, 25)],[NSValue valueWithCGPoint:CGPointMake(25, 200)],[NSValue valueWithCGPoint:CGPointMake(200, 200)]];
    //3
    group.duration = 2.0;
    group.autoreverses = YES;
    group.repeatCount = 3;
    group.animations = @[animation1,animation2];

    
    [self.myview.layer addAnimation:group forKey:@"asd"];

//第三种

<pre name="code" class="objc">CATransition *ani = [CATransition animation];
    /*
     pageCurl            向上翻一页
     pageUnCurl          向下翻一页
     rippleEffect        滴水效果
     suckEffect          收缩效果,如一块布被抽走
     cube                立方体效果
     oglFlip             上下翻转效果
     */
    ani.type = @"cube";
    ani.repeatCount = 200;
    ani.duration = 1;
    //方向
    ani.subtype = kCATransitionFromLeft;
    [self.myview.layer addAnimation:ani forKey:@"an"];









IOS 动画

标签:style   io   ar   color   os   sp   for   on   art   

原文地址:http://blog.csdn.net/shichangbu123/article/details/41521051

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!