【问题标题】:xcode presentModalViewController leaves old ViewController still active in background using AVCamxcode presentModalViewController 使用 AVCam 使旧的 ViewController 在后台仍然处于活动状态
【发布时间】:2012-11-09 18:47:36
【问题描述】:

使用 AVCam 的应用程序出现问题。该应用程序拍摄照片并将它们保存到胶卷。打开应用程序后,它会完美地拍摄照片并以应有的方式保存它们。但是,一旦我离开该视图控制器转到另一个视图控制器然后返回,它会保存图像旋转 90 度的正常肖像图像。确实很奇怪的活动。

在拉了很多头发之后,我想也许我正在尝试运行太多会话,所以我确保在 viewdidload 中结束会话并且 viewdiddisappear:

-(void)viewDidUnload{
if([[self captureManager] session ]){
    [[[self captureManager] session] stopRunning];
    self.captureManager = nil;
}
}

-(void)viewDidDisappear:(BOOL)animated{
if([[self captureManager] session ]&&rollCancel==NO){
    [[[self captureManager] session] stopRunning];
     self.captureManager = nil;
}
}

还是不行。离开后仍然保存不正确。

我像这样改变视图: -(void)openMenu{
MenuViewController * vc = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil]; [自我presentModalViewController:vc动画:YES]; [自我dismissViewControllerAnimated:没有完成:无]; }

也试过了:

-(void)openMenu{

[self dismissViewControllerAnimated:NO completion:^{
    MenuViewController * vc = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
    [self presentModalViewController:vc animated:YES];
    [self dismissViewControllerAnimated:NO completion:nil];
}];    
}

我不需要释放,因为我在 arc 上运行。这也不起作用,我什至无法使用此选项更改屏幕。所以,我添加了一个计时器来查看在我离开视图控制器后操作是否会继续执行:

updateTimer = [NSTimer timerWithTimeInterval: 5.0
                                      target: self selector: @selector(autoTimer)
                                    userInfo: nil repeats: YES];
[[NSRunLoop mainRunLoop] addTimer: updateTimer forMode: NSDefaultRunLoopMode];

-(void)autoTimer{
NSLog(@"blablabla");
}

毫不奇怪,即使离开视图控制器,blablabla 也会继续打印到我的控制台中。如果我来回走动,它会不断创建新的重复计时器并在我的控制台日志中发送垃圾邮件。

这与我的应用程序在返回屏幕后没有正确保存有关。这意味着执行 presentmodalviewcontroller 实际上并不会从运行中删除所有内容。

有没有其他人遇到过类似的问题,或者知道如何在视图控制器之间切换时真正清除它们?

【问题讨论】:

    标签: xcode nstimer presentmodalviewcontroller


    【解决方案1】:

    没有解决仍在后台运行的 NSTimer,但确实修复了与在后台打开的东西无关的景观问题

    在这里找到解决方案:https://stackoverflow.com/a/6335992/1688727

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 2016-05-30
      • 2020-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多