2014-10-10 41 views
2

enter image description here我想寫一個自定義賽格瑞和所遇到的這個錯誤不平衡通話開始爲/終端外形的轉變:在<UIViewController中0x176c0bd0>導航控制器

不平衡通話開始/結束的外觀轉變爲的UIViewController:0x176c0bd0

幫助按鈕連接到幾乎是空的ViewController - 和退出按鈕解開SEGUE

所有的控制器AR嵌入在導航控制器中。

我已經閱讀了各種帖子,在這裏人們遇到同樣的問題,但解決方案變化很大,我仍然沒有找到合適的解決方案。我認爲這是因爲我在導航控制器中調用了自定義的segue,但是我的代碼沒有反映出這一點。我已經按照本教程中創建自定義SEGUE http://blog.dadabeatnik.com/2013/10/13/custom-segues/

初始控制器具有以下方法:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([segue isKindOfClass:[ICIHelpSegue class]]) { 
     ((ICIHelpSegue *)segue).originatingPoint = self.help.center; 
    }  
} 

- (IBAction)unwindFromViewController:(UIStoryboardSegue *)sender { 
} 

- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier { 
    ICIUnwindHelpSegue *segue = [[ICIUnwindHelpSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController]; 
    segue.targetPoint = self.help.center; 
    return segue; 
} 

的ICIHelpSegue類是如下界面:

@interface ICIHelpSegue : UIStoryboardSegue 

    @property CGPoint originatingPoint; 
    @property CGPoint targetPoint; 

    @end 

和實現文件看起來像這樣:

@implementation ICIHelpSegue 
- (void)perform { 
    UIViewController *sourceViewController = self.sourceViewController; 
    UIViewController *destinationViewController = self.destinationViewController; 
    UINavigationController *navigationController = sourceViewController.navigationController; 

    [navigationController.view addSubview:destinatiionViewController.view] 

    // Transformation start scale 
    destinationViewController.view.transform = CGAffineTransformMakeScale(0.05, 0.05); 

    // Store original centre point of the destination view 
    CGPoint originalCenter = destinationViewController.view.center; 
    // Set center to start point of the button 
    destinationViewController.view.center = self.originatingPoint; 

    [UIView animateWithDuration:0.5 
          delay:0.0 
         options:UIViewAnimationOptionCurveEaseInOut 
        animations:^{ 
         // Grow! 
         destinationViewController.view.transform = CGAffineTransformMakeScale(1.0, 1.0); 
         destinationViewController.view.center = originalCenter; 
        } 
        completion:^(BOOL finished){ 
         [destinationViewController.view removeFromSuperview]; // remove from temp super view 
         [navigationController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC 
        }]; 
} 

@end 

任何ide爲什麼會出現這種錯誤?這是什麼意思?以及如何解決它?

+0

只是一個想法。你嘗試刪除這一行:'[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL];'??? – lucaslt89 2014-10-10 15:16:07

+0

是的,但沒有幫助。但我已經找到了一種消除錯誤的方法 - 我聲明瞭UINavigationController * navigationController = sourcerViewController.navigationController;然後,我做[navigationController.view addSubview:destinationViewController]然後在完成塊我調用[navigationController.view removeFromSuperview]這擺脫了錯誤,但它看起來不是很好,所以我留下的問題,看看如果有人能告訴我更好的解決方案,或者幫我弄清楚發生了什麼。我對此很陌生,只會猜測一半的時間。 – 2014-10-10 15:24:03

+0

我們需要看看故事板如何連接。你能發佈你的故事板segues連接的截圖嗎? – lucaslt89 2014-10-10 15:28:30

回答

7

我有同樣的錯誤。這個問題似乎與調用presentViewController的removeFromSuperview在同一個運行循環中被調用:animated:對於相同的viewController/view完成。

有一兩件事可以做,以擺脫這種警告是延遲之後呈現視圖控制器:

completion:^(BOOL finished) 
    { 
     destinationViewController.view removeFromSuperview]; 
     [navigationController performSelector:@selector(presentViewController:) withObject:destinationViewController afterDelay:0]; 
    }]; 

} 

-(void)presentViewController:(UIViewController*)viewController 
{ 
    [[self presentViewController:viewController animated:NO completion:nil]; 
} 

然而,無論這種方法和一個與警告有時有閃爍,因爲有是一個框架,視圖已從超級視圖中刪除,但尚未顯示。

爲了解決這個問題,你可以創建目標視圖控制器的快照視圖,並添加到視圖層次結構代替實際destinationViewController的觀點,然後將其刪除後的destinationViewController已經呈現:

completion:^(BOOL finished) 
    { 
     UIView * screenshotView = [destinationViewController.view snapshotViewAfterScreenUpdates:NO]; 

     screenshotView.frame = destinationViewController.view.frame; 

     [destinationViewController.view.superview insertSubview:screenshotView aboveSubview: destinationViewController.view]; 
     [destinationViewController.view removeFromSuperview]; 

     [self performSelector:@selector(presentViewControllerRemoveView:) withObject:@[destinationViewController, screenshotView] afterDelay:0]; 


    }]; 
} 

-(void)presentViewControllerRemoveView:(NSArray *)objects 
{ 
    UIViewController * viewControllerToPresent = objects[0]; 
    UIView * viewToRemove = objects[1]; 

    [self presentViewController:viewControllerToPresent 
         animated:NO 
        completion: 
    ^{ 
     [viewToRemove removeFromSuperview]; 
    }]; 
} 
+0

謝謝你,已經發現這是runloop的問題,但現在已經知道如何停止閃爍。你救了我幾個小時的我的頭髮! – Bulwinkel 2015-05-09 05:10:59

相關問題