以下代码是循环中的动画按钮。
[UIView setAnimationRepeatCount: 0];
self.introButton.transform = CGAffineTransformMakeScale(1.1, 1.1);
[UIView animateWithDuration: 0.4
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations: ^{
self.introButton.transform = CGAffineTransformIdentity;
}completion: ^(BOOL finished){
//Code
}];
但是,添加此动画后,我无法再通过内部动作获取按钮。我该如何制作动画并采取行动?
答案 0 :(得分:2)
在动画中加入UIViewAnimationOptionAllowUserInteraction
选项。
UIView animateWithDuration: 0.4
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction
animations: ^{
self.introButton.transform = CGAffineTransformIdentity;
}completion: ^(BOOL finished){
//Code
}];
文档说:
在动画期间,对正在设置动画的视图暂时禁用用户交互。 (在iOS 5之前,对整个应用程序禁用用户交互。)如果希望用户能够与视图交互,请在options参数中包含UIViewAnimationOptionAllowUserInteraction常量
答案 1 :(得分:0)
您似乎需要将动画视图与响应点按
的视图分开UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[UIView animateWithDuration: 0.4
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations: ^{
button.transform = CGAffineTransformMakeScale(1.1, 1.1);
}completion: ^(BOOL finished){
//Code
}];
UIView *frontView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
frontView.backgroundColor = [UIColor clearColor];
[self.view addSubview:frontView];
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh:)];
[frontView addGestureRecognizer:gr];