1

试图通过一种方法隐藏和显示视图,但它似乎应该可以显示和隐藏,但它是即时的。

- (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
    }
}

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

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

4

0 回答 0