3

hidesBarOnSwipeプロパティに問題があります。UINavigationControllerです。UINavigationController hidesBarOnSwipeメモリリークの問題

概要:

Link to project file

私はUINavigationControllerのルート図であるFirstViewControllerという名前のコントローラを持っています。 すべてはMain.storyboardです。 FirstViewControllerには、UIButtonアクションが含まれています。そのアクションの中で、私はSecondViewControllerをインスタンス化し、それをナビゲーションスタックにプッシュします。

- (IBAction)button:(id)sender { 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; 

    [self.navigationController pushViewController:vc animated:YES]; 
} 

インサイドSecondViewControllerはviewDidLoadYESにのみhidesBarsOnSwipeプロパティセットがあります:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.navigationController.hidesBarsOnSwipe = YES; 
} 

とのdeallocはNSLoggedます:

- (void)dealloc { 
    NSLog(@"Dealloc"); 
} 

問題:

ナビゲーションバーを隠すようにスワイプすると、deallocが呼び出されることはありません。 InstrumentsではSecondViewControllerのメモリリークを示しています。

私たちがSecondViewController上にあって、ちょうど戻るボタンを押すと、すべてが問題ありません。 Deallocが呼び出されます。

一定の種類の保持サイクルがありますが、このような状況を避ける理由と回避方法がわかりません。

+2

ちょうど同じ問題があります。 Xcode 9.2(ベータ版) –

+0

これはiOS 11以降の問題です。 iOS 10.3- –

答えて

0

一部の更新や一時的な解決策:

navigationBar隠蔽を実行するための別の方法があります。 何私のために働いたことは使用することです:

[self.navigationController setNavigationBarHidden:hidden animated:YES]; 

を良い結果を達成するためには、navigationBarアニメーションのトラックの状態を維持するために、あなたのクラスのプロパティを追加します。

@property (assign, nonatomic) BOOL statusBarAnimationInProgress; 

は、このようなUIScrollViewDelegateを実装します。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    CGFloat yVelocity = [scrollView.panGestureRecognizer velocityInView:scrollView].y; 
    if (yVelocity > 0 && !self.statusBarAnimationInProgress) { 
     [self setNavigationBarHidden:NO]; 
    } else if (yVelocity < 0 && !self.statusBarAnimationInProgress) { 
     [self setNavigationBarHidden:YES]; 
    } 
} 

設定されたナビゲーションバーの設定は、次のようになります。

- (void)setNavigationBarHidden:(BOOL)hidden { 
    [CATransaction begin]; 
    self.statusBarAnimationInProgress = YES; 
    [CATransaction setCompletionBlock:^{ 
     self.statusBarAnimationInProgress = NO; 
    }]; 
    [self.navigationController setNavigationBarHidden:hidden animated:YES]; 
    [CATransaction commit]; 
} 

CATransactionを使用して、ナビゲーションバーのアニメーションが完了しているかどうかを確認します。どのような方法でも動作します。あまり簡単な解決策ではなく、少なくとも漏れはありません:)

関連する問題