pop动画实践(一)


#import "POP.h"

#import "POPSpringPOPLayerSize.h"

#import "POPSpringPOPLayerPosition.h"

#import "POPSpringPOPViewFrame.h"


#import "POPBasicPOPViewAlpha.h"


/*

    POPSpringAnimation  有弹簧效果的动画类

    

    POPBasicAnimation 基本动画类

    

    POPDecayAnimation 衰减动画类

    

    POPCustomAnimation 可以自定义动画的类

     */

1.给一个视图加动画

//用POPSpringAnimation 让viewBlue实现弹性放大缩小的效果
    POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];
    
    CGRect rect = _springView.frame;
    if (rect.size.width==100) {
        springAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(300, 300)];
    }
    else{
        springAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(100, 100)];
    }
    

    //弹性值
    springAnimation.springBounciness = 20.0;
    //弹性速度
    springAnimation.springSpeed = 20.0;

    [_springView.layer pop_addAnimation:springAnimation forKey:@"changesize"];




2.弹窗类似于UIAletView

//用POPSpringAnimation让viewBlue实现弹性放大缩小的效果
    POPSpringAnimation *springAnimation = [POPSpringAnimationanimationWithPropertyNamed:kPOPLayerSize];
    
    CGRect rect =_springView.frame;
    if (rect.size.width==100) {
        springAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(300,300)];
    }
    else{
        springAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(100,100)];
    }
    

    //弹性值
    springAnimation.springBounciness =20.0;
    //弹性速度
    springAnimation.springSpeed =20.0;

    [_springView.layerpop_addAnimation:springAnimationforKey:@"changesize"];




3.拉抻图片 

POPSpringAnimation *springAnimation = [POPSpringAnimationanimationWithPropertyNamed:kPOPViewFrame];
    
    CGPoint point = [taplocationInView:self.view];
    
    springAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0, point.x, point.y)];
    
    
    //弹性值
    springAnimation.springBounciness =20.0;
    //弹性速度
    springAnimation.springSpeed =20.0;
    
    [_springViewpop_addAnimation:springAnimationforKey:@"changeframe"];




4.改透明度动画

POPBasicAnimation *anim = [POPBasicAnimationanimationWithPropertyNamed:kPOPViewAlpha];
    
    anim.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    float alpha =_basicView.alpha;
    if (alpha==1.0) {
        anim.toValue =@(0.0);
    }
    else{
        anim.toValue =@(1.0);
    }
    
    [_basicViewpop_addAnimation:animforKey:@"alpha"];


5.隐藏或者


    _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)];
    
    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;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值