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

有谁知道为什么不呢?

4

1 回答 1

0

你躲在categoryView后面commitAnimations。所以它会在一开始就被隐藏起来,你将无法看到动画。

您可以使用“旧方式”beginAnimations等,并使用setAnimationDidStopSelector:并隐藏那里的视图。

或者您通过使用块来使用最新的方式:

[UIView animateWithDuration:0.2
 animations:^{
    // your animations
 }
 completion:^(BOOL finished){ 
    // hide the view
 }];
于 2013-02-14T12:39:32.090 回答