Programing

iOS7 UIModalTransitionStyleFlipHorizontal 전환 후 바운스

lottogame 2020. 10. 25. 11:29
반응형

iOS7 UIModalTransitionStyleFlipHorizontal 전환 후 바운스


iOS 7 용 앱을 업데이트하고 있는데 이상한 문제를 발견했습니다. 나는 UINavigationController에 싸인 UIViewController를 UIModalTransitionStyleFlipHorizontal.

iOS 6에서는 제대로 작동하지만 iOS 7에서는 전환 후 탐색 모음이 튀어 나옵니다. 상태 표시 줄과 관련이 있습니까? 기본 탐색 모음의 반투명도를 NO.

Info.plist에서 View 컨트롤러 기반 상태 표시 줄 모양 이 NO로 설정되어 있습니다.

그리고 다음은 최소 데모 앱의 문제를 보여주는 GIF입니다.

여기에 이미지 설명 입력

내 코드는 다음과 같습니다.

feedNavigationController = [[UINavigationController alloc] init];
feedNavigationController.navigationBar.translucent = NO;

SettingsViewController *settingsVC = [[SettingsViewController alloc] init];

feedNavigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[feedNavigationController setViewControllers:[NSArray arrayWithObjects:settingsVC, nil]];

[self presentViewController:feedNavigationController animated:YES completion:nil];

이것은 UIKit 버그로 보입니다. 다음 해결 방법은 문제를 해결하는 것 같습니다.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}

(이를 전환 하려는 뷰 컨트롤러에 배치하십시오 ).


현재 및 닫기에 대한이 문제를 해결하기 위해 iOS7 사용자 정의 전환을 사용합니다.

이것을 UIViewController에 추가하십시오.

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    return (id<UIViewControllerAnimatedTransitioning>)self;
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return (id<UIViewControllerAnimatedTransitioning>)self;
}

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
    return 0.7f;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    UIView *containerView = [transitionContext containerView];


    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    [containerView addSubview:fromVC.view];

    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    [containerView addSubview:toVC.view];

    UIViewAnimationOptions animationOption = ([toVC.presentedViewController isEqual:fromVC])?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;


    [UIView transitionFromView:fromVC.view
                        toView:toVC.view
                      duration:[self transitionDuration:transitionContext]
                       options:animationOption
                    completion:^(BOOL finished) {
                        [transitionContext completeTransition:YES];
                    }];
}

이를 사용하려면 iOS7에 있는지 확인하고 transitionDelegate를 설정해야합니다.

YourVCWithTheCustomTransition* yourVC = [[YourVCWithTheCustomTransition alloc] init];

CGFloat deviceVersion = [UIDevice currentDevice].systemVersion.floatValue;
if(deviceVersion >= 7.0) [yourVC setTransitioningDelegate:yourVC];

[self presentModalViewController:yourVC animated:YES];
[yourVC release];

제 경우에는 사용자 지정 전환이 정의 된 사용자 지정 UINavigationController가 있습니다. 매번이 작업을 수행 할 필요가 없습니다.


이것은 UIKit 버그로 보입니다. 다음 해결 방법은 문제를 해결하는 것 같습니다.

presentViewController (전환하려는 뷰 컨트롤러에 이것을 배치하십시오) :

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}

dismissViewControllerAnimated (당신이 무시한 뷰 컨트롤러에 이것을 배치하십시오) :

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}

사용하지 않는 경우 autolayout. 뷰 컨트롤러에 다음 dismiss추가해야합니다 .

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [self.view setNeedsLayout];
} 

I had the same issue and could "solve it" (it's not a real solution to the problem but it looks fine :) ). The trick is present the view controller using pushViewController/popViewController with an UIView animation to make a flip. Here is a example code to present the view controller:

UIViewController *viewController = [[UIViewController alloc] init];
[UIView transitionWithView:self.navigationController.view 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionFlipFromLeft 
                animations:^{
                   [self.navigationController pushViewController:viewController animated:NO];
                }
                completion:nil];

To dismiss it:

[UIView transitionWithView:self.navigationController.view 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionFlipFromRight 
                animations:^{
                   [self.navigationController popViewControllerAnimated:NO];
                }
                completion:nil];

If you don't want the navigationBar on the pushed controller just call [self.navigationController setNavigationBarHidden:YES animated:NO] in viewWillAppear. I hope this approach help you.


For both the presenting and the presented view controller I have a UITableViewController within UINavigationController, both configured using Auto Layout. I noticed that the other answers didn't solve the problem that on dismiss the tableView of the presenting view controller jumps 20 pt vertically.

This solution addresses this problem.

In the presented view controller (as proposed by Ben Packard):

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar.layer removeAllAnimations];
}

프레젠테이션 뷰 컨트롤러에서 (부분적으로 더스티가 제안한대로) :

- (void)viewWillLayoutSubviews{
    if (self.navigationController.presentedViewController) {
        [self.navigationController.navigationBar.layer removeAllAnimations];
        [self.tableView.layer removeAllAnimations];
    }
    [super viewWillLayoutSubviews];
}

저도 마찬가지입니다. 실제로 효과가 있었던 것은 스타일을 CoverVertical로 변경하는 것입니다.

참고 URL : https://stackoverflow.com/questions/18781519/ios7-uimodaltransitionstylefliphorizontal-bounces-after-transition

반응형