2011-10-24 41 views
0

的ImageView的下禁用我的應用程序滾動視圖,我有「分頁啓用」,當我選擇了一個頁面的ImageView的開始它的動畫以這種方式IOS:動畫

- (void) beginWinAnimation{ 
[UIView animateWithDuration:2.5 
       animations:^{successView.alpha = 1.0;} 
       completion:^(BOOL finished){ 

       [UIView animateWithDuration:2.5 
       animations:^{successView.alpha = 0;}]; 
       }];} 

在這個動畫我一個滾動視圖可以看到這個successView下的滾動視圖,我可以移動滾動視圖頁面;我希望在動畫過程中不能移動滾動視圖,但只有在動畫完成時纔有可能?

回答

1

是的,這是可能的。當動畫開始設置時[scrollView setScrollEnabled:NO];動畫完成後,將其設置回YES

因此,在你的代碼,它看起來像 -

- (void) beginWinAnimation{ 

[scrollView setScrollEnabled:NO]; 

[UIView animateWithDuration:2.5 
       animations:^{ 
        successView.alpha = 1.0; 
       } 
       completion:^(BOOL finished){ 
        [UIView animateWithDuration:2.5 
         animations:^{successView.alpha = 0;} 
         completion:^(BOOL finished){ 
          [scrollView setScrollEnabled:YES]; 
         }]; 
       }];} 

見,如果這個工程。

+0

你能改變我的代碼嗎? – CrazyDev

+0

這是一個完全正確的答案;我猜想''userInteractionEnabled'作爲'scrollEnabled'的替代方法''UIScrollView'從'UIView'繼承的'userInteractionEnabled'值得一提,作爲一種更一般的方法。 – Tommy

+0

因爲@blackguardian只希望阻止滾動,所以只有阻止滾動纔有意義。我們可以通過關閉「userInteractionEnabled」來實現相同的行爲,但是屏幕上的所有內容都變得無法使用。這導致了一些醜陋的可用性問題。所以... –