POP初步认识之POPAnimatableProperty

2017-03-28  本文已影响0人  1ac244776e12

项目初期因为需要用到动画展示,便写了自带的

[UIView animateWithDuration:2.0 animations:^{

CGRect frame = self.theGreenView.frame;

frame.origin.x+= 200;

self.theGreenView.frame = frame;

} completion:^(BOOL finished) {

}

}];

随着需求的增加、需要时时的展示控件的X坐标,上面方法不能满足需求了。

然后开始集成pop的POPAnimatableProperty进行自定义动画,目的是改变imageview的x轴坐标

官方地址 https://github.com/facebook/pop

POPAnimatableProperty *prop = [POPAnimatableProperty propertyWithName:@"countdown" initializer:^(POPMutableAnimatableProperty *prop) {

prop.writeBlock = ^(id obj, const CGFloat values[]) {

//            NSLog(@"values==%f",(float)values[0]);

[imageview setLeft:(float)values[0]];

};

//        prop.threshold = 0.01f;

}];

POPBasicAnimation *anBasic = [POPBasicAnimation linearAnimation];  //

anBasic.property = prop;    //自定义属性

anBasic.fromValue = @(imageview.left);  //获取imageview的初始x轴坐标  

anBasic.toValue = @(value);  //imageview  的x轴坐标

anBasic.duration = 10;    //持续时间

anBasic.beginTime = CACurrentMediaTime() ;    //开始时间

[imageview pop_addAnimation:anBasic forKey:@"countdown"];

上一篇 下一篇

猜你喜欢

热点阅读