Ios 如何始终使用facebook POP轮换一半?

Ios 如何始终使用facebook POP轮换一半?,ios,facebook,facebook-pop,Ios,Facebook,Facebook Pop,我是iOS新手 我希望在用户单击按钮时始终旋转一半 下面是代码,当我单击它时,它只旋转一次,不再旋转 @property UIButton *button; - (void)viewDidLoad { [super viewDidLoad]; CGFloat buttonSize = 220; self.button = [UIButton buttonWithType:UIButtonTypeCustom]; self.button.backgroundColor = [UI

我是iOS新手

我希望在用户单击按钮时始终旋转一半

下面是代码,当我单击它时,它只旋转一次,不再旋转

@property UIButton *button;

- (void)viewDidLoad {
  [super viewDidLoad];
  CGFloat buttonSize = 220;
  self.button = [UIButton buttonWithType:UIButtonTypeCustom];
  self.button.backgroundColor = [UIColor colorFromHexString:@"#B084C7"];
  self.button.frame = CGRectMake(0, 0, buttonSize, buttonSize);
  [self.button addTarget:self
                action:@selector(didTap:)
      forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:self.button];
}

- (void)didTap:(id)sender {
  POPSpringAnimation *anim = [self.button.layer pop_animationForKey:@"rotate"];
  if (anim) {
    anim.toValue = @(M_PI * 0.5);
  } else {
    anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];
    anim.toValue = @(M_PI * 0.5);
    anim.springSpeed = 3;
    anim.springBounciness = 1;
  }
  [self.button.layer pop_addAnimation:anim forKey:@"rotate"];
}

始终旋转到相同的值
@(M_PI*0.5)
这是应用于层的绝对旋转。如果要增加角度,则需要执行以下操作:

anim.toValue = @(anim.fromValue.floatValue + (M_PI * 0.5));