Liang's Blog

Dont worry,be happy.

Pop Demo

| Comments

利用弹跳动画写一个视图拉伸

1.创建一个视图,并为视图添加拖拽手势

1
2
3
4
5
6
self.testView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
    self.testView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.testView];

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
[self.view addGestureRecognizer:panGestureRecognizer];

2.响应手势做动画变换

1
2
3
4
5
6
7
8
9
10
11
12
13
POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPosition];
    positionAnimation.velocity = [NSValue valueWithCGPoint:velocity];//速度
    positionAnimation.dynamicsTension = 5;//延伸
    positionAnimation.dynamicsFriction = 15.0f;//摩擦
    positionAnimation.springBounciness = 20.0f;//弹跳
  [self.testView.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];//位置变换


      POPSpringAnimation *sizeAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];
    sizeAnimation.velocity = [NSValue valueWithCGPoint:velocity];
    sizeAnimation.springBounciness = 1.0f;
    sizeAnimation.dynamicsFriction = 1.0f;
    [self.testView.layer pop_addAnimation:sizeAnimation forKey:@"sizeAnimation"]; //大小变换

可以看到两个pop弹跳动画,主要是名字不同kPOPLayerPosition ,kPOPLayerSize。

原创作品,转载请注明出处,谢谢。

Comments