POP常用的4个类
POPSpringAnimation 有弹性效果的动画类
POPBasicAnimation 基本动画类
POPDecayAnimation 衰减动画类
POPCustomAnimation 可以自定义动画的类
//用POPSpringAnimation 让view实现弹性放大缩小的效果
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];
CGRect rect = view.frame;
if (rect.size.width==50) {
springAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(100, 100)];
}
else{
springAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(50, 50)];
}
//弹性值
springAnimation.springBounciness = 20.0;
//弹性速度
springAnimation.springSpeed = 20.0;
[View.layer pop_addAnimation:springAnimation forKey:@"changesize"];
//用POPSpringAnimation 让view实现弹性改变位置的效果
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPosition];
CGPoint point = View.center;
if (point.y==120) {
springAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(point.x, -200)];
}
else{
springAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(point.x, 120)];
}
//弹性值
springAnimation.springBounciness = 20.0;
//弹性速度
springAnimation.springSpeed = 20.0;
[View pop_addAnimation:springAnimation forKey:@"changeposition"];
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
CGPoint point =CGPointMake(200, 200);
springAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, point.x, point.y)];
//弹性值
springAnimation.springBounciness = 20.0;
//弹性速度
springAnimation.springSpeed = 20.0;
[View pop_addAnimation:springAnimation forKey:@"changeframe"];
//用POPBasicAnimation 让view实现透明度变化的效果
POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
float alpha = View.alpha;
if (alpha==1.0) {
anim.toValue = @(0.0);
}
else{
anim.toValue = @(1.0);
}
[View pop_addAnimation:anim forKey:@"alpha"];
//初始化第一个视图块
if (self.myView==nil) {
self.myView=[[UIView alloc]initWithFrame:CGRectMake(0, 80, 30, 30)];
self.myView.backgroundColor=[UIColor redColor];
[self.view addSubview:self.myView];
}
//创建一个POPDecayAnimation动画 实现X轴运动 减慢速度的效果 通过速率来计算运行的距离 没有toValue属性
POPDecayAnimation *anSpring = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anSpring.velocity = @(100); //速率
anSpring.beginTime = CACurrentMediaTime() + 1.0f;
[anSpring setCompletionBlock:^(POPAnimation *prop, BOOL fint) {
if (fint) {
NSLog(@"myView=%@",NSStringFromCGRect(self.myView.frame));
}
}];
[self.myView pop_addAnimation:anSpring forKey:@"myViewposition"];