2013-02-14 46 views
0

我想動畫和緩慢調暗背景,當我提出一個選擇器。然後,當我把它放下時,我想慢慢地將它製作回來。出於某種原因,它只是在我提出pickerView時起作用,而不是當它想要把它放下時。事情不動畫回

此代碼:

-(IBAction)chooseCategory:(id)sender{ 
    [self.chooseCategoryView setHidden:NO]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.4]; 
    self.categoryPicker.frame = CGRectMake(0, 151, 320, 367); 
    self.categoryPickerToolbar.frame = CGRectMake(0, 106, 320, 45); 
    self.pickerViewBackground.alpha = 0.6; 
    [UIView commitAnimations]; 
    [self.scrollView setUserInteractionEnabled:NO]; 
} 

但這並不

-(IBAction)hideCategory:(id)sender { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.4]; 
    self.pickerViewBackground.alpha = 0; 
    self.categoryPicker.frame = CGRectMake(0, 545, 320, 367); 
    self.categoryPickerToolbar.frame = CGRectMake(0, 500, 320, 367); 
    [UIView commitAnimations]; 
    [self.chooseCategoryView setHidden:YES]; 
    [self.scrollView setUserInteractionEnabled:YES]; 
} 

任何人都知道爲什麼不?

+0

只是刪除[self.chooseCategoryView setHidden:YES];來自hideCategory。它立即隱藏您的視圖。 – 2013-02-14 12:41:24

回答

0

您正在隱藏categoryView之後commitAnimations。所以它會在一開始就隱藏起來,你將無法看到動畫。

您可以使用beginAnimations等的「舊方式」,並使用setAnimationDidStopSelector:並在那裏隱藏視圖。

或者你採用模塊使用了最新的方法:

[UIView animateWithDuration:0.2 
animations:^{ 
    // your animations 
} 
completion:^(BOOL finished){ 
    // hide the view 
}];