44.pop学习

来源:互联网 发布:如何注销淘宝会员名 编辑:程序博客网 时间:2024/05/09 07:29
#import "ZWYViewController.h"
#import
 "pop/POP.h"



@interface ZWYViewController ()
@property (readwrite, assign) BOOL timerRunning;

@property (readwrite, assign) BOOL isOpened;

@property (nonatomic, retain) UIView *mView;

@property (nonatomic, assign) CGRect hidePosition;
@property (nonatomic, assign) CGRect showPosition;
@property (nonatomic, retain) UIView *popView;
@property (nonatomic, retain) UIView *tempView;

@property (nonatomic, retain) UIView *springView;
@property (nonatomic, retain) UIView *springView2;//改变position
@end

@implementation ZWYViewController

- (
void)viewDidLoad
{
    [
super viewDidLoad];

   
 _mView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
    [
_mView.layer setShadowColor:[[UIColor grayColor] CGColor]];
   
   
 _mView.backgroundColor = [UIColor yellowColor];;
    [
_mView setClipsToBounds:NO];
    [
_mView.layer setShadowOpacity:1.0];
    [
self.view addSubview:_mView];
   
    [
_mView.layer setShadowOffset:CGSizeMake(-20, 0)];
   
//    [UIView beginAnimations:@"status" context:nil];
//    [UIView setAnimationDuration:3];
////    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//    [UIView setAnimationDelegate:self];
////    [UIView setAnimationDidStopSelector:@selector(removeNetStatusLabel)];
////    [mView.layer setShadowOffset:CGSizeMake(-10, -10)];
//    _mView.frame = CGRectMake(200, 50, 50, 50);
//    [UIView commitAnimations];
   
   
   
 _timerRunning = YES;
   
    [
self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(demoAnimate:)]];
   
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"+" style:UIBarButtonItemStyleDone target:self action:@selector(showPop)];

    [
_mView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPop)]];
   
 _hidePosition = CGRectMake(320, 64, 0, 0);
   
 _showPosition = CGRectMake(220, 64, 100, 120);
   
 _isOpened = NO;
    [
_popView setClipsToBounds:YES];
   
 _popView = [[UIView alloc] initWithFrame:_hidePosition];
   
 _popView.backgroundColor = [UIColor redColor];
   
 _tempView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 80, 100)];
   
 _tempView.backgroundColor = [UIColor blueColor];
    [
_popView addSubview:_tempView];
    [
self.view addSubview:_popView];
   
   
   
   
 _springView = [[UIView alloc] initWithFrame:CGRectMake(60, 140, 100, 100)];
   
 _springView.backgroundColor = [UIColor blueColor];
   
 UITapGestureRecognizer *gestureForSpring = [[UITapGestureRecognizer alloc] init];
    [gestureForSpring
 addTarget:self action:@selector(changeSize:)];
    [
_springView addGestureRecognizer:gestureForSpring];
    [
self.view addSubview:_springView];
   
   
 _springView2 = [[UIView alloc] initWithFrame:CGRectMake(20, -230, 280, 200)];
   
 _springView2.backgroundColor = [UIColor cyanColor];
   
 UITapGestureRecognizer *gestureForSpring2 = [[UITapGestureRecognizer alloc] init];
    [gestureForSpring2
 addTarget:self action:@selector(changePosition:)];
    [
_tempView addGestureRecognizer:gestureForSpring2];
    [
self.view addSubview:_springView2];
   
   
 UITapGestureRecognizer *gestureForSpring3 = [[UITapGestureRecognizer alloc] init];
    [gestureForSpring3
 addTarget:self action:@selector(changeFrame:)];
    [
_springView2 addGestureRecognizer:gestureForSpring3];
}
//改变frame
- (
void)changeFrame:(UIPanGestureRecognizer*)tap{
   
 POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
   
 CGPoint point = [tap locationInView:self.view];
    springAnimation.
toValue = [NSValue valueWithCGRect:CGRectMake(_springView2.frame.origin.x, _springView2.frame.origin.y, point.x - _springView2.frame.origin.x, point.y - _springView2.frame.origin.y)];
   
 //弹性值
    springAnimation.
springBounciness = 20.0;
   
 //弹性速度
    springAnimation.
springSpeed = 20.0;
   
    [
_springView2 pop_addAnimation:springAnimation forKey:@"changeframe"];
}

//透明度
- (
void)demoAnimate:(UITapGestureRecognizer*)tap
{
   
 _timerRunning = !_timerRunning;
   
   
 POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
    anim.
timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim.
fromValue = @(0.0);
    anim.
toValue = @(1.0);
   
   
 if (_timerRunning) {
        anim.
fromValue = @(0.0);
        anim.
toValue = @(1.0);
    }
   
 else {
        anim.
fromValue = @(1.0);
        anim.
toValue = @(0.0);
    }
    [
_mView pop_addAnimation:anim forKey:@"fade"];
}

//改变大小
- (
void)changeSize:(UITapGestureRecognizer*)tap{
   
   
 //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"];
   
}

- (
void)changePosition:(UITapGestureRecognizer*)tap{
   
   
 POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPosition];
   
   
 CGPoint point = _springView2.center;
   
   
 if (point.y==240) {
        springAnimation.
toValue = [NSValue valueWithCGPoint:CGPointMake(point.x, -230)];
    }
   
 else{
        springAnimation.
toValue = [NSValue valueWithCGPoint:CGPointMake(point.x, 240)];
    }
   
   
 //弹性值
    springAnimation.
springBounciness = 20.0;
   
 //弹性速度
    springAnimation.
springSpeed = 20.0;
   
    [
_springView2 pop_addAnimation:springAnimation forKey:@"changeposition"];
   
}

//显示弹出
- (
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;
   
   
 POPSpringAnimation *positionAnimation1 = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    positionAnimation1.
fromValue = [NSValue valueWithCGRect:CGRectMake(100, 0, 0, 0)];
    positionAnimation1.
toValue = [NSValue valueWithCGRect:CGRectMake(10, 10, 80, 100)];
    positionAnimation1.
springBounciness = 8.0f;
    positionAnimation1.
springSpeed = 15.0f;
    [
_popView pop_addAnimation:positionAnimation forKey:@"frameAnimation"];
    [
_tempView pop_addAnimation:positionAnimation1 forKey:@"frameAnimation1"];
   
}
//隐藏弹出
- (
void)hidePop{
   
 POPBasicAnimation *positionAnimation1 = [POPBasicAnimation animationWithPropertyNamed:kPOPViewFrame];
    positionAnimation1.
fromValue = [NSValue valueWithCGRect:CGRectMake(10, 10, 80, 100)];
    positionAnimation1.
toValue = [NSValue valueWithCGRect:CGRectMake(100, 0, 0, 0)];
//    positionAnimation1.springBounciness = 15.0f;
//    positionAnimation1.springSpeed = 20.0f;
   
 POPBasicAnimation *positionAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewFrame];
    positionAnimation.
fromValue = [NSValue valueWithCGRect:_showPosition];
    positionAnimation.
toValue = [NSValue valueWithCGRect:_hidePosition];
   
 //key一样就会用后面的动画覆盖之前的
   
    [
_tempView pop_addAnimation:positionAnimation1 forKey:@"frameAnimation1"];
   
    [
_popView pop_addAnimation:positionAnimation forKey:@"frameAnimation"];
   
   
 _isOpened = NO;
}

- (
void)didReceiveMemoryWarning
{
    [
super didReceiveMemoryWarning];
   
 // Dispose of any resources that can be recreated.
}

@end
0 0
原创粉丝点击