【问题标题】:Thing doesn't animate back东西没有动画回来
【发布时间】:2013-02-14 12:28:13
【问题描述】:

当我调出选择器时,我想为背景设置动画并慢慢变暗。然后当我把它放下时,我想慢慢地把它动画化。出于某种原因,它只在我打开 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];
}

有人知道为什么没有吗?

【问题讨论】:

  • 只需删除 [self.chooseCategoryView setHidden:YES];从隐藏类别。它会立即隐藏您的视图。

标签: ios objective-c animation beginanimations


【解决方案1】:

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

您可以将“旧方式”与beginAnimations 等一起使用,然后使用setAnimationDidStopSelector: 并在那里隐藏视图。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多