zoukankan      html  css  js  c++  java
  • Facebook开源动画库 POP-小实例

    实例1:图片视图跟着手在屏幕上的点改变大小

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        //添加手势
        UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] init];
        [gesture addTarget:self action:@selector(changeSize:)];
        [self.view addGestureRecognizer:gesture];
        
    }
    
    - (void)changeSize:(UIPanGestureRecognizer*)tap{
        POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    
        CGPoint point = [tap locationInView:self.view];
        springAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, point.x, point.y)];
    
        //弹性值
        springAnimation.springBounciness = 20.0;
        //弹性速度
        springAnimation.springSpeed = 20.0;
        [_springView pop_addAnimation:springAnimation forKey:@"changeframe"];
    
    }

    实例2:实现一个弹出收缩视图的效果,弹出来有弹性的效果,收缩有变小的效果

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        _showPosition = CGRectMake(320-147, 5, 147, 160);
        _hidePosition = CGRectMake(320, 5, 0, 0);
        
        _popView = [[UIImageView alloc] initWithFrame:_hidePosition];
        _popView.image = [UIImage imageNamed:@"menu.png"];
        [self.view addSubview:_popView];
    
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"+" style:UIBarButtonItemStyleDone target:self action:@selector(showPop)];
        
        //让屏幕从导航栏下开始算(0,0)
        if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
            self.edgesForExtendedLayout = UIRectEdgeNone;
        }
    }
    
    - (void)showPop{
        
        if (_isOpened) {
            [self hidePop];
            return;
        }
        _isOpened = YES;
        
        POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
        positionAnimation.fromValue = [NSValue valueWithCGRect:_hidePosition];
        positionAnimation.toValue = [NSValue valueWithCGRect:_showPosition];
        positionAnimation.springBounciness = 15.0f;
        positionAnimation.springSpeed = 20.0f;
        [_popView pop_addAnimation:positionAnimation forKey:@"frameAnimation"];
    }
    
    - (void)hidePop{
        
        POPBasicAnimation *positionAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewFrame];
        positionAnimation.fromValue = [NSValue valueWithCGRect:_showPosition];
        positionAnimation.toValue = [NSValue valueWithCGRect:_hidePosition];
        [_popView pop_addAnimation:positionAnimation forKey:@"frameAnimation"];
     
        _isOpened = NO;
    }

    实例3:创建两个按键,增加两个动画效果,其中一个按键是动画改变大小,另外一个修改ViewFrame,只要定位好坐标跟大小可以做出很不错的动画

    @interface ViewController ()
    
    @property (nonatomic, retain) UIView *button;
    @property (nonatomic, retain) UIView *popOut;
    @property (readwrite, assign) BOOL timerRunning;
    
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        _popOut = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TimerPopOut"]];
        [_popOut setFrame:CGRectMake(245, 70, 0, 0)];
        [self.view addSubview:_popOut];
        
        _button = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TimerButton"]];
        [_button setFrame:CGRectMake(240, 50, 46, 46)];
        [self.view addSubview:_button];
        
        _timerRunning = NO;
        
        [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(demoAnimate:)]];
    }
    
    
    - (void)demoAnimate:(UITapGestureRecognizer*)tap
    {
        _timerRunning = !_timerRunning;
        
        POPSpringAnimation *buttonAnimation = [POPSpringAnimation animation];
        buttonAnimation.property = [POPAnimatableProperty propertyWithName:kPOPLayerSize];
        if (_timerRunning) {
            buttonAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(37, 37)];
        }
        else {
            buttonAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(46, 46)];
        }
        buttonAnimation.springBounciness = 10.0;
        buttonAnimation.springSpeed = 10.0;
        [_button pop_addAnimation:buttonAnimation forKey:@"pop"];
        
        
        POPSpringAnimation *popOutAnimation = [POPSpringAnimation animation];
        popOutAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewFrame];
        if (!_timerRunning) {
            popOutAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(245, 70, 0, 10)];
        }
        else {
            popOutAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(180, 60, 75, 26)];
        }
        popOutAnimation.velocity = [NSValue valueWithCGRect:CGRectMake(200, 0, 300, -200)];
        popOutAnimation.springBounciness = 10.0;
        popOutAnimation.springSpeed = 10.0;
        [_popOut pop_addAnimation:popOutAnimation forKey:@"slide"];
    }
  • 相关阅读:
    SpringCloud笔记(一)服务注册与发现
    个人备忘录
    ActiveMQ 消息持久化到Mysql数据库
    染色 [组合数 容斥]
    各种图床
    NOIP2012 疫情控制
    网格计数
    找钱 [多重背包 计数]
    序列[势能线段树]
    牛客挑战赛33 B-鸽天的放鸽序列
  • 原文地址:https://www.cnblogs.com/wujy/p/5202062.html
Copyright © 2011-2022 走看看