項目初期因為需要用到動畫展示,便寫了自帶的
[UIView animateWithDuration:2.0 animations:^{
CGRect frame = self.theGreenView.frame;
frame.origin.x+= 200;
self.theGreenView.frame = frame;
} completion:^(BOOL finished) {
}
}];
隨著需求的增加、需要時時的展示控件的X坐標(biāo),上面方法不能滿足需求了。
然后開始集成pop的POPAnimatableProperty進行自定義動畫,目的是改變imageview的x軸坐標(biāo)
官方地址 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軸坐標(biāo) ?
anBasic.toValue = @(value);? //imageview ?的x軸坐標(biāo)
anBasic.duration = 10;? ? //持續(xù)時間
anBasic.beginTime = CACurrentMediaTime() ;? ? //開始時間
[imageview pop_addAnimation:anBasic forKey:@"countdown"];