Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UINavigationController隐藏BARONSWIPE内存泄漏问题_Ios_Objective C_Memory Leaks_Uinavigationcontroller_Uinavigationbar - Fatal编程技术网

Ios UINavigationController隐藏BARONSWIPE内存泄漏问题

Ios UINavigationController隐藏BARONSWIPE内存泄漏问题,ios,objective-c,memory-leaks,uinavigationcontroller,uinavigationbar,Ios,Objective C,Memory Leaks,Uinavigationcontroller,Uinavigationbar,我对UINavigationController的hidesbaronsweep属性有问题 概述: 我有一个名为FirstViewController的控制器,它是UINavigationController的根视图。 一切都在Main.storyboard中。 FirstViewController包含ui按钮操作。在该操作中,我实例化了SecondViewController并将其推送到导航堆栈上 - (IBAction)button:(id)sender { UIStoryboa

我对
UINavigationController
hidesbaronsweep
属性有问题

概述:

我有一个名为FirstViewController的控制器,它是
UINavigationController
的根视图。 一切都在
Main.storyboard
中。 FirstViewController包含
ui按钮
操作。在该操作中,我实例化了SecondViewController并将其推送到导航堆栈上

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

    [self.navigationController pushViewController:vc animated:YES];
}
在SecondViewController中,只有一个
HidesBarsSwipe
属性在
viewDidLoad
上设置为
YES

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.hidesBarsOnSwipe = YES;
}
并且dealloc会被记录:

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

当我们向上滑动以隐藏导航栏时,dealloc永远不会被调用。Instruments在此显示第二个ViewController内存泄漏

当我们在SecondViewController上,只需按“后退”按钮,一切都很好。Dealloc被调用


确实存在某种保留周期,但我不知道为什么以及如何避免这种情况

一些更新和临时解决方案:

还有另一种方法可以执行导航栏隐藏。 对我有用的是使用:

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

我使用CATTransaction检查导航栏的动画是否完成。任何可行的方法。这不是一个简单的解决方案,但至少没有泄漏:)

也遇到了同样的问题。Xcode 9.2(beta版)这似乎是iOS 11+的问题。在iOS 10.3上一切正常-
- (void)setNavigationBarHidden:(BOOL)hidden {
    [CATransaction begin];
    self.statusBarAnimationInProgress = YES;
    [CATransaction setCompletionBlock:^{
        self.statusBarAnimationInProgress = NO;
    }];
    [self.navigationController setNavigationBarHidden:hidden animated:YES];
    [CATransaction commit];
}