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"];
}
时间: 2024-10-10 16:07:41

Facebook开源动画库 POP-小实例的相关文章

使用 Facebook开源动画库 POP 实现真实衰减动画

1. POP动画基于底层刷新原理.是基于CADisplayLink,1秒钟运行60秒,接近于游戏开发引擎 @interface ViewController () @property (nonatomic,strong)CADisplayLink *displayLink; @property (nonatomic)      NSInteger     count; @end - (void)viewDidLoad { [superviewDidLoad]; self.displayLink

使用 Facebook 开源动画库 POP 实现真实衰减动画

1. POP 动画基于底部刷新原理,是基于CADisplayLink,1秒钟执行60秒,接近于游戏开发引擎 @interface ViewController () @property (nonatomic,strong)CADisplayLink *displayLink; @property (nonatomic)      NSInteger     count; @end - (void)viewDidLoad { [superviewDidLoad]; self.displayLink

Facebook开源动画库 POP-POPBasicAnimation运用

动画在APP开发过程中还是经常出现,将花几天的时间对Facebook开源动画库 POP进行简单的学习:本文主要针对的是POPBasicAnimation运用:实例源代码已经上传至gitHub,地址:https://github.com/wujunyang/facebookPopTest POP默认支持三种动画 但同时也支持自定义动画 POPBasicAnimation //基本动画 POPSpringAnimation //类似弹簧一般的动画效果 POPDecayAnimation //过阻尼效

Facebook开源动画库 POP-POPSpringAnimation运用

POPSpringAnimation也许是大多数人使用POP的理由 其提供一个类似弹簧一般的动画效果:实例源代码已经上传至gitHub,地址:https://github.com/wujunyang/facebookPopTest POPSpringAnimation可配置的属性与默认值为 springBounciness:4.0    //[0-20] 弹力 越大则震动幅度越大 springSpeed     :12.0   //[0-20] 速度 越大则动画结束越快 dynamicsTens

[转] iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么?

iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么? http://www.zhihu.com/question/23654895/answer/25541037 拿 Canvas 来和 Pop 比其实不大合适,虽然两者都自称「动画库」,但是「库」这个词的含义有所区别.本质上 Canvas 是一个「动画合集」而 Pop 是一个「动画引擎」. 先说 Canvas.Canvas 的目的是「Animate in Xcode Without Code」.开发者可以通过在 Storyboar

tweenjs缓动算法使用小实例

这里的tweenjs不是依托于createjs的tewwnjs,而是一系列缓动算法集合.因为本身是算法,可以用在各个业务场景中,这也正是总结学习它的价值所在.tweenjs代码详情: 1 /* 2 * Tween.js 3 * t: current time(当前时间): 4 * b: beginning value(初始值): 5 * c: change in value(变化量): 6 * d: duration(持续时间). 7 * you can visit 'http://easing

Facebook Rebound 弹性动画库 源码分析

Rebound源码分析 让动画不再僵硬:Facebook Rebound Android动画库介绍一文中介绍了rebound这个库. 对于想体验一下rebound的效果,又懒得clone和编译代码的,这里提供一个demo apk. 今天看到了tumblr发布了基于rebound的Backboard,本想直接分析一下Backboard对rebound做了些什么,不过考虑到rebound还没有仔细分析过,所以这里做一下源码分析. 对外部来说,首先接触的就是SpringSystem了,但在说它之前,先

让动画不再僵硬:Facebook Rebound Android动画库介绍

introduction official site:http://facebook.github.io/reboundgithub : https://github.com/facebook/reboundRebound是facebook推出的一个弹性动画库,可以让动画看起来真实自然,像真实世界的物理运动,带有力的效果,使用的参数则是facebook的origami中使用的.官网上有一个简单的JS版本来做demo,如果说到evernote.LinkedIn.flow等应用也在使用这个动画库,是

Rebound-Android的弹簧动画库

简介 官方网站 github Rebound是facebook出品的一个弹簧动画库,与之对应的iOS版本有一个pop动画库,也是非常的强大给力.Facebook真是互联网企业中的楷模,开源了很多的实用开源库,大赞一个!!! 讲解Rebound之前,先看看我们根据Rebound高仿的新浪微博弹出菜单,看效果图: 话说回来,facebook为啥推出这个库呢?主要就是现有的动画离真实物理世界差别比较明显,为了让动画看起来真实自然,带有力量的效果,Rebound应运而生.两个比较重要的参数,一个是拉力T