我在我的應用程序中有一個UInaviguationController。我的問題是如何在將viewController推送到當前場景的視圖時製作backgroundView。默認是黑屏。我希望實現類似於在UINaviguationController中呈現Modally而不是當前上下文的東西。當推入UI導航時更改背景控制器
0
A
回答
0
比方說,你是從視圖控制器A到視圖控制器B.
你可以嘗試像服用右背景視圖的屏幕截圖您在使用導航控制器推B之前。
UIGraphicsBeginImageContextWithOptions(targetView.bounds.size, NO, 0);
[targetView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
然後通過此圖像查看控制器B並將其設置爲背景圖像。如果您還希望與以模態方式呈現視圖控制器相同的動畫,則必須使用自定義導航控制器動畫並進行設置。
編輯:如果你想要做的一切都表明B上的相同的純色爲A的只需設置B的背景色是A和添加自定義導航控制器動畫
對於動畫, 您必須將View Controller設置爲navigationController的委託。然後您將不得不添加以下代理功能:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
return [[Slide alloc] init];
}
然後返回您要創建的類來實現動畫。你將不得不讓你做出一流符合<UIViewControllerAnimatedTransitioning>
協議
的類必須實現以下兩個代表職能 -
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext{
return 0.4f;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
UIViewController* toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView* container = [transitionContext containerView];
[container addSubview:toController.view];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
//set frame to be out of screen bounds here
} completion:^(BOOL finished) {
[fromController.view removeFromSuperview];
[transitionContext completeTransition:finished];
}];
}
相關問題
- 1. iOS導航控制器背景故障
- 2. UI塊,而在推視圖控制器導航控制器
- 3. 如何隱藏導航欄,當我從導航控制器推?
- 4. 將視圖控制器推入導航控制器
- 5. 將視圖控制器推入導航控制器的問題
- 6. 更改在U導航控制器中添加的UIImage的背景圖像
- 7. 如何更改導航背景色CSS
- 8. 更改導航標題背景顏色
- 9. 更改導航欄背景顏色?
- 10. 更改導航欄的背景
- 11. 如何更改導航欄背景
- 12. 當推新視圖時,導航控制器爲空
- 13. 當鼠標進入區域時改變控制背景
- 14. 導航控制器+段控制器:無法更改視圖
- 15. 推進和彈出導航控制器?
- 16. 推導航控制器,不支持
- 17. 從UIScrollView推導航控制器
- 18. 推的UIViewController沒有導航控制器
- 19. 設置導航視圖控制器的背景
- 20. 在導航控制器內的UIViewController中設置背景
- 21. iPad導航控制器景觀問題
- 22. 導航控制器和視圖導航時不更新
- 23. 導航抽屜在滾動時更改背景
- 24. 在更改導航控制器中更改文本顏色
- 25. Tab控制器正在被導航控制器推送
- 26. 導航控制器推送 - 視圖 - 控制器
- 27. 推控制器後隱藏導航控制器
- 28. 導航控制器推零視圖控制器錯誤
- 29. 在導航控制器上推TabBar控制器
- 30. 推兩個導航控制器的視圖控制器
謝謝,你可以爲你解答迅速的版本?另外如何通過拍攝的圖像? – user2232305
在目標C中的頭文件中設置一個強大的UIImage屬性。當您編寫推視圖控制器B的代碼時,您必須編寫 ViewControllerB.image = yourImage; 對不起,我不是很熟悉迅速,並可能最終誤導你。我已經告訴過你如何做到客觀C,你應該能夠迅速做出想法並做到這一點。 – Rikh