2014-09-13 71 views
1

以下代碼是循環中的動畫按鈕。將動畫添加到按鈕後,目標操作會丟失

[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 
         }]; 

然而,加入這個動畫後,我沒有更多的能夠獲得按鈕潤色內行動。我如何動畫和獲取動作?

回答

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之前,整個應用程序都禁用了用戶交互。)如果您希望用戶能夠與視圖交互,請在選項參數中包含UIViewAnimationOptionAllowUserInteraction常量

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]; 
+0

這會起作用,但實際上並非如此必須去解決這個問題。 – 2014-09-13 15:22:18

+0

@JesseRusak是的你是對的。在這裏學習新東西:) – dopcn 2014-09-13 15:28:54