uiview animateWithDuration无法隐藏在相同的切换方法中

时间:2014-08-04 22:50:05

标签: objective-c uiview animatewithduration

尝试隐藏并显示来自单个方法的视图,但它似乎应该可以显示和隐藏它的瞬间。

- (void)toggleMyView:(BOOL)show
{
    CGRect orig = self.originalMyViewFrame; // original frame of the view
    CGRect offScreen = CGRectMake(orig.origin.x, self.view.frame.size.height, orig.size.width, orig.size.height);
    if (show) {
        self.myView.frame = offScreen; // set off screen
        self.myView.hidden = NO; // unide the view
        [UIView animateWithDuration:0.5 animations:^{
            self.myView.frame = orig; // animate to original position
        }];
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            self.myView.frame = offScreen; // animate off screen
        } completion:^(BOOL finished) {
            self.myView.hidden = YES; // hide when animation finished
        }];
    }
}

如果我删除隐藏逻辑,它会很好地动画。

- (void)toggleMyView:(BOOL)show
{
    CGRect orig = self.originalMyViewFrame; // original frame of the view
    CGRect offScreen = CGRectMake(orig.origin.x, self.view.frame.size.height, orig.size.width, orig.size.height);
    if (show) {
        self.myView.frame = offScreen; // set off screen
        self.myView.hidden = NO; // unide the view
        [UIView animateWithDuration:0.5 animations:^{
            self.myView.frame = orig; // animate to original position
        }];
    } else {
        self.myView.hidden = YES; // hide when animation finished
    }
}

我不明白为什么要添加隐藏逻辑中断。

这可能是内存保留周期问题吗?

0 个答案:

没有答案