我有一個攝像頭視圖控制器。我想推它。但是我希望它在我推動時淡入。我該怎麼做呢。我沒有使用UINavigationController。自定義UIViewController動畫沒有UINAVIGATIONCONTROLLER
0
A
回答
2
您將視圖控制器「推入」導航堆棧。但是,當您呈現沒有導航控制器的視圖控制器時,您將其命名爲「present」(而不是「push」)。意味着術語「推」視圖控制器很難連接到UINavigationController
。
所以你可以只是谷歌的東西像「UIViewController自定義過渡」或類似的東西。
I did great success following a this great article by Teehan+Lax。只要讀它,它應該引導你正確的方式。
編輯好的。我會添加一些信息爲您提供更好的答案。
首先,您將創建的NSObject
一個新的子類,符合UIViewControllerAnimatedTransitioning
協議:
@interface JWTransitionAnimator <UIViewControllerAnimatedTransitioning>
+ (JWTransitionAnimator *)transitionAnimatorForPresentation;
+ (JWTransitionAnimator *)transitionAnimatorForDismissal;
@end
然後你讓你實現魔術發生:
@interface JWTransitionAnimator()
@property (atomic, assign, getter=isPresenting) BOOL presenting;
@end
@implementation JWTransitionAnimator
+ (JWTransitionAnimator *)transitionAnimatorForPresentation {
JWTransitionAnimator *animator = [[self alloc] init];
[animator setPresenting:YES];
return animator;
}
+ (JWTransitionAnimator *)transitionAnimatorForDismissal {
return [[self alloc] init];
}
// implement the protocol:
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitioningContext {
return 0.3; // or any other duration.
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitioningContext {
UIViewController *fromViewController = [transitioningContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext UITransitionContextToViewController];
UIView *fromView = [fromViewController view];
UIView *toView = [toViewController view];
if ([self isPresenting]) {
[fromView setUserInteractionEnabled:NO];
[[transitionContext containerView] addSubview:fromView];
[[transitionContext containerView] addSubview:toView];
[toView setAlpha:0.0];
[toView setTransform:CGAffineTransformScale([fromView transform], 0.3, 0.3)];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
[fromView setTintAdjustmentMode:UIViewTintAdjustmentModeDimmed];
[toView setAlpha:1.0];
[toView setTransform:CGAffineTransformScale([toView transform], 1.0, 1.0)];
} completion:^(BOOL finished) {
[transitionContext completeTransition:finished];
}];
}
else {
// reverse your animation here (change "fromView" for "toView" and vice-versa)
}
}
您呈現viewController必須符合UIViewControllerTransitionDelegate
協議。實現它如下:
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
return [JWTransitionAnimator transitionAnimatorForPresentation];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
return [JWTransitionAnimator transitionAnimatorForDismissal];
}
在你目前的視圖控制器是這樣的:
- (IBAction)presentViewController:(id)sender {
UIViewController *yourVC = [[UIViewController alloc] init]; // however you create it
[yourVC setModalPresentationStyle:UIModalPresentationStyleCustom];
[yourVC setTransitionDelegate:self];
[self presentViewController:yourVC animated:YES completion:NULL];
}
相關問題
- 1. 自定義UINavigationController動畫:CATransition
- 2. 自定義的UINavigationController動畫
- 3. UINavigationController自定義過渡動畫
- 4. iPhone - UINavigationController - 自定義動畫與CATransaction
- 5. UINavigationController中的UITableView自定義動畫
- 6. 使用UIViewController自定義動畫
- 7. 自定義UINavigationController帶性能問題的推/動畫動畫
- 8. 自定義UINavigationController
- 9. UINavigationController自定義動畫防止從工作中滑動回去
- 10. 自定義segue將特定的UIViewController推送到UINavigationController
- 11. UINavigationController presentModalViewController在rootviewcontroller沒有出現動畫
- 12. UINavigationController沒有按照想要的動畫
- 13. 沒有UINavigationController的Push Segue動畫
- 14. 自定義UINavigationController UINavigationBar
- 15. UINavigationController自定義titleView
- 16. UINavigationController的自定義過渡動畫視圖控制器alpha值
- 17. UINavigationController上的自定義titleView動畫不正確
- 18. 爲UINavigationController的自定義動畫推不正確
- 19. 流行UIViewController與自定義「解僱模態」般的動畫
- 20. 如何創建一個自定義的UIViewController過渡動畫?
- 21. 如何設置自定義解僱動畫的UIViewController
- 22. 推送一個UIViewController的自定義動畫
- 23. 的UINavigationController推動UIViewController中並沒有任何反應
- 24. 有沒有辦法用AngularJS創建自定義動畫事件
- 25. UINavigationController動畫
- 26. UINavigationController titleView動畫
- 27. ios uinavigationcontroller到uiviewcontroller
- 28. 自定義UINavigationController實現
- 29. 自定義UINavigationController UIToolbar子類
- 30. UINavigationController的自定義轉換