zoukankan      html  css  js  c++  java
  • ios各种动画的实现效果(转)

    原文地址http://blog.sina.com.cn/s/blog_884e78b20100u0pp.html

    第一种:
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:kDuration];//动画时间
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];//第一个参数:动画类型
    NSUInteger green = [[self.view subviews] indexOfObject:self.greenView];
    NSUInteger blue = [[self.view subviews] indexOfObject:self.blueView];
    [self.view exchangeSubviewAtIndex:green withSubviewAtIndex:blue];
    [UIView setAnimationDelegate:self];
     // 动画完毕后调用某个方法
     //[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    [UIView commitAnimations];

    第二种:
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = kDuration;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.type = kCATransitionFade;//动画类型
    animation.subtype = kCATransitionFromLeft;//动画方向
    NSUInteger green = [[self.view subviews] indexOfObject:self.greenView];
    NSUInteger blue = [[self.view subviews] indexOfObject:self.blueView];
    [self.view exchangeSubviewAtIndex:green withSubviewAtIndex:blue];
    [[self.view layer] addAnimation:animation forKey:@"animation"];

    动画类型还有:

    1. 2.用字符串表示 
    2.      pageCurl            向上翻一页 
    3.      pageUnCurl          向下翻一页 
    4.      rippleEffect        滴水效果 
    5.      suckEffect          收缩效果,如一块布被抽走 
    6.      cube                立方体效果 
    7.      oglFlip             上下翻转效果  
    8.      cameraIrisHollowOpen  iphone相机打开效果
    9.      cameraIrisHollowOpen 关闭相机的效果
    10. */ 


    第三种:
    [UIView animateWithDuration:1 animations:^{
            [[self.view.subviews objectAtIndex:0] setAlpha:1];
            [[self.view.subviews objectAtIndex:1] setAlpha:0];
            NSUInteger green = [[self.view subviews] indexOfObject:self.greenView];
            NSUInteger blue = [[self.view subviews] indexOfObject:self.blueView];
            [self.view exchangeSubviewAtIndex:green withSubviewAtIndex:blue];
        }];

    还有其他类型的调用方法,这个是最简单的,可以加上其他的参数进行一些操作。
    第二个参数是一个代码快,来执行VIEW的属性改变,系统会将视图从当前状态平滑的过度到最终状态(就是你做修改之后的状态)。
    可以被改变的属性有:
    frame
    bounds
    center
    transform //可以实现3D/2D效果
    alpha
    backgroundColor
    contentStretch

    比如 self.view.layer.transform = CATransform3DMakeRotation(1, -1, -1, 1); 可以在代码中将整个VIEW动画旋转(这里只是一个例子,有效果,但是不怎么好看)

    上面是3D变化,如果是2d的,那么就应该修改view上的transform ,而不应该按照上面的代码。

  • 相关阅读:
    @Autowired和@Resource注解的注入顺序
    八大排序算法(Java实现)+ 自制动画
    一文秒杀三个经典面试求和问题
    这篇文章,或许对还在上学的你,有一些帮助
    得了,一文把前缀和给扒的干干净净了。
    BF,BM,KMP,就这?
    那个贼贵的比特币到底是什么原理?
    小样?别以为你穿了几个马甲就不认得你是二分法!
    面试前必知必会的二分查找及其变种
    Vue.js 官方示例初探
  • 原文地址:https://www.cnblogs.com/xiaobaizhu/p/3100351.html
Copyright © 2011-2022 走看看