#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;
}