2013-02-24 58 views
1

我有一個運行良好,直到我升級到4.6的Xcode的應用程序。在升級xcode 4.6之後,在ios4上運行時沒有收到觸摸事件(在ios5和ios6上正常工作)。我嘗試在IB中添加一個開關(沒有連接,只是添加)。我可以在ios5和ios6設備上的模擬器中切換開關,但是在ios4上我甚至不能移動開關。animateWithDuration升級後造成的iOS4的觸摸事件問題的Xcode 4.6

我有一個計時器運行的小動畫:

- (void)setFoamSize:(float)foamSize 
{  
    // foamSize is a number between 0 - 100. 0 is min foam size; 100 is max foam size 

    // NSLog(@"setFoamSize %f", foamSize); 

    float centerX, centerY; 
    float minHeight, minWidth; 
    float maxHeight, maxWidth; 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    { 
     centerX  = 70.0; 
     centerY  = 102.0f; 

     minWidth = 51.0f; 
     minHeight = 37.0f; 

     maxWidth = 111.0f; 
     maxHeight = 86.0f; 
    } 
    else 
    { 
     centerX  = 158.0f; 
     centerY  = 151.0f; 

     minWidth = 74.0f; 
     minHeight = 64.0f; 

     maxWidth = 320.0f; 
     maxHeight = 271.0f; 
    } 


    float height = ((maxHeight - minHeight) * foamSize + minHeight); 
    float width = ((maxWidth - minWidth) * foamSize + minWidth); 

    float x = centerX - width/2; 
    float y = centerY - height/2; 

    float alpha = MIN(1.0, ((1.0 - 0.7) * foamSize + 0.7)); 

    @autoreleasepool { 

     [UIView animateWithDuration:1.0 
           delay:0.0 
          options: UIViewAnimationOptionCurveLinear 
         animations:^{ 
          imageViewFoam.frame = CGRectMake(x, y, width, height); 
          imageViewFoam.alpha = alpha; 
         } 
         completion:^(BOOL finished){ 
         }]; 
    } 

} 

如果我註釋掉這個動畫,然後使觸摸事件在IOS 4動畫在所有iOS的作品收到,並採取了屏幕的一小部分(即不與任何按鈕或開關重疊)。

爲什麼會變成這樣的動畫與觸摸事件的干擾?

更新

如果我移動animateWithDuration外的影像學改變,一切正常(即觸摸事件的iOS4接收)

imageViewFoam.frame = CGRectMake(x, y, width, height); 
imageViewFoam.alpha = alpha; 


@autoreleasepool { 

    [UIView animateWithDuration:1.0 
          delay:0.0 
         options: UIViewAnimationOptionCurveLinear 
        animations:^{ 
         //imageViewFoam.frame = CGRectMake(x, y, width, height); 
         //imageViewFoam.alpha = alpha; 
        } 
        completion:^(BOOL finished){ 
        }]; 
} 

更新2

每隔1秒就會開始播放動畫(所以持續時間也是1秒),圖像的增長相對平滑,略有鋸齒,但是我想要的效果)。

在任何情況下,如果我改變持續時間0.5秒,然後觸摸如果觸摸對象在動畫之間(但如果他們在動畫過程中會碰到的)事件工作。

因此,似乎同時animationWithDuration實際上是動畫的東西,那一抹事件在iOS4的忽略。

回答

3

我添加了一些選項UIViewAnimationOptionAllowUserInteraction

@autoreleasepool { 

    [UIView animateWithDuration:1.0 
          delay:0.0 
         options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) 
        animations:^{ 
         imageViewFoam.frame = CGRectMake(x, y, width, height); 
         imageViewFoam.alpha = alpha; 
        } 
        completion:^(BOOL finished){ 
        }]; 
} 

由於MMC的回答here

據蘋果docs動畫應該只禁用imageViewFoam

用戶交互過程中的動畫,用戶 動作中涉及的所有視圖暫時被禁用而不管此 屬性中的值如何。您可以通過配置 動畫時指定 UIViewAnimationOptionAllowUserInteraction選項來禁用此行爲。

所以我不知道爲什麼事情沒有工作。在任何 的情況下,添加選項解決了我的問題。