zoukankan      html  css  js  c++  java
  • 使用CATransition实现页面的“从左向右” “从右向左”的动画

    -(void)initView{
        UISwipeGestureRecognizer *left_gesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(action:)];
        [left_gesture setDirection:UISwipeGestureRecognizerDirectionLeft];
        UISwipeGestureRecognizer *right_gesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(action:)];
        [right_gesture setDirection:UISwipeGestureRecognizerDirectionRight];
        [self.view addGestureRecognizer:left_gesture];
        [self.view addGestureRecognizer:right_gesture];
    }
    
    -(void)action:(UISwipeGestureRecognizer *)gesture{
        CATransition *animation = [CATransition animation];
        [animation setValue:@"swipe" forKey:@"name"];
        animation.type = kCATransitionReveal;
        if (gesture.direction==UISwipeGestureRecognizerDirectionLeft) {
             animation.subtype = kCATransitionFromRight;
            [self.view setBackgroundColor:[UIColor redColor]];
        }else if(gesture.direction==UISwipeGestureRecognizerDirectionRight){
            animation.subtype = kCATransitionFromLeft;
            [self.view setBackgroundColor:[UIColor blueColor]];
        }
        
           [self.view.layer addAnimation:animation forKey:@"animation"];
    }
  • 相关阅读:
    各种模板
    HNOI2019总结
    WC2019游记
    THUSC2017 Day1题解
    NOIP2018联赛总结
    LOJ2557. 「CTSC2018」组合数问题
    NOI2018游记
    bzoj4671: 异或图
    sg函数小结
    [NOI2011]Noi嘉年华
  • 原文地址:https://www.cnblogs.com/niit-soft-518/p/4238253.html
Copyright © 2011-2022 走看看