2014-10-07 58 views
0

我想創建一個使用UIStoryboardSegue子類的新視圖控制器的自定義過渡,但我遇到了一些問題。我有一個後退按鈕,使用AutoLayout將其設置爲距離頂部佈局指南(距離視圖頂部25個像素)爲5個像素。但是,當我正在過渡時,我的視圖不考慮狀態欄的存在,並使按鈕距離視圖頂部5個像素,而不是距離視圖頂部25個像素(status-bar.height = = 20px)。所以當轉換完成後,當我調用[[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO]時突然反彈;因爲那時按鈕實際上會正確分層。有沒有人有任何想法,我可以告訴我的觀點,它應該佈局,假設頂部佈局指南開始在20px而不是0?UIStoryBoardSegue過渡 - 狀態欄問題

編輯:這個問題似乎與topLayoutGuide直接相關。當我檢查topLayoutGuide的值時,它是0,當我在轉換中添加視圖時,但是當我在目標視圖控制器的viewDidAppear中檢查它時,它是20像它應該是。

- (void)perform { 
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; 
UIViewController *sourceViewController = (UIViewController*)self.sourceViewController; 
UIViewController *destinationViewController = (UIViewController*)self.destinationViewController; 

[destinationViewController.view setCenter:CGPointMake(window.frame.size.width * 1.5, sourceViewController.view.center.y)]; 
[[sourceViewController.view superview] addSubview:destinationViewController.view]; 
[destinationViewController.view setBackgroundColor:[UIColor redColor]]; 

POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX]; 
positionAnimation.toValue = @(window.center.x); 
positionAnimation.springBounciness = 10; 


POPSpringAnimation *fromPositionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX]; 
double offScreenX = -sourceViewController.view.frame.size.width; 
fromPositionAnimation.toValue = @(offScreenX); 
fromPositionAnimation.springBounciness = 10; 
[fromPositionAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) { 
}]; 

POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; 
scaleAnimation.springBounciness = 20; 
scaleAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(1.0, 1.1)]; 
[scaleAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) { 
    [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO]; 
}]; 

[sourceViewController.view.layer pop_addAnimation:fromPositionAnimation forKey:@"positionAnimation"]; 
[destinationViewController.view.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"]; 
[destinationViewController.view.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"]; 

}

enter image description here

回答

0

我建議叫setNeedLayout上viewWillAppear中。它應該調整視圖子視圖的佈局。

+0

setNeedsLayout沒有工作。我試圖在目標視圖控制器的viewWillAppear中調用它,並且在將目標視圖添加到源視圖的超級視圖後,我也在UIStoryBoardSegue子類中嘗試了它。 – Homeschooldev 2014-10-07 20:19:05

+0

該問題與topLayoutGuide有關。我測試了它以確保。當我正在轉換topLayoutGuide爲0時,並且在viewDidAppear中,目標視圖控制器的topLayoutGuide爲20,這應該是。關於這是爲什麼的想法? – Homeschooldev 2014-10-07 20:45:54

+0

我發現了一個類似的問題[here](http://stackoverflow.com/questions/20312765/navigation-controller-top-layout-guide-not-honored-with-custom-transition)。我希望它能幫助你。 – Alex 2014-10-07 21:53:49