2012-10-29 15 views
0

以下函數應該A.使視圖變大B.等待5秒鐘C.再縮小它。問題是A瞬間發生,而不是在兩秒鐘內發生。鏈接的動畫:第一個是即時的

- (void) showAndHide { 
CGRect r = self.frame; 
float right = r.origin.x + r.size.width, h = r.size.height, y = r.origin.y; 

[UIView animateWithDuration:2 
         delay:0 
        options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction 
       animations:^{ 
        self.frame = CGRectMake(right - 400, y, 400, h); 
        [UIView animateWithDuration:2 
              delay:5 
             options: UIViewAnimationOptionOverrideInheritedCurve | 
         UIViewAnimationOptionCurveLinear | 
         UIViewAnimationOptionOverrideInheritedDuration 
             animations:^{ 
              self.frame = CGRectMake(right - 40, y, 40, h); 
             } 
             completion:nil]; 

       } 
       completion:nil]; 

}

可能是什麼造成的?提前致謝!

回答

0

放入第一個完成處理的第二個動畫:

- (void) showAndHide { 
CGRect r = self.frame; 
float right = r.origin.x + r.size.width, h = r.size.height, y = r.origin.y; 

[UIView animateWithDuration:2 
         delay:0 
        options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction 
       animations:^{ 
        self.frame = CGRectMake(right - 400, y, 400, h); 
       } 
       completion:^{ 
       [UIView animateWithDuration:2 
             delay:5 
            options: UIViewAnimationOptionOverrideInheritedCurve | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionOverrideInheritedDuration 
             animations:^{ 
              self.frame = CGRectMake(right - 40, y, 40, h); 
             } 
             completion:NULL]; 
       }]; 
} 

與方法的問題是,這兩個動畫同時排隊。如果您想堅持使用您的代碼,我認爲將UIViewAnimationOptionBeginFromCurrentState添加到第二個動畫的選項中可能會解決您的問題。雖然不太確定。