The UIWindow's background application is jumping at the top of views when I switch from a view content to a UITableView

故事扮演 提交于 2020-01-16 03:49:05

问题


I am in charge to update an application in IOS8. But I have a problem when I want to switch between two view (the old and the new). The background of the UIWindow's Application jumped. It appears during 1 second and disappear. I can not find the issue. I tap on a backButton to change the content view.

- (void)onBackTap
    {
        NSLog(@"Standard back");

        [self goBackWithAnimation:AnimatePushFromLeft];
    }


- (void)goBackWithAnimation:(GraphNavigationAnimation)animation
    {
        NSLog(@"History Before ---> %@", [self currentHistory]);

        [[self currentHistory] removeLastObject];
        NSLog(@"History After ---> %@", [self currentHistory]);

        self.currentVC = [[self currentHistory] lastObject];

        [view_ switchContentViewTo:currentVC_.view
            navigationItemStack:[[self currentHistory] valueForKey:@"navigationItem"]
            isNavbarVisible:navbarVisible_
            animation:animation];

    }

Thank you for your support if you have already found a solution.

This is my procedure to switch from an old and a new contentView:

-(void)switchContentViewTo:(UIView *)newView navigationItemStack:(NSArray*)navigationItemStack isNavbarVisible:(BOOL)isNavbarVisible animation:GraphNavigationAnimation)animation {
    BOOL isPrevNavbarVisible = navbarVisible_;
    navbarVisible_ = isNavbarVisible;

    if (!contentView_) {
        contentView_ = newView;
        [self insertSubview:contentView_ belowSubview:navbar_];
        [navbar_ setItems:navigationItemStack animated:NO];

        [self setNeedsLayout];
        return;
    }

    if (newView == contentView_) {
        [navbar_ setItems:navigationItemStack animated:NO];
        return;
    }

    CGRect const bigFrame = self.bounds;
    CGRect const smallFrame = CGRectMake(0, navbarHeight_,
        self.bounds.size.width, self.bounds.size.height - navbarHeight_);

    CGRect centerFrame = isNavbarVisible
        ? smallFrame
        : bigFrame;

    void (^step1)(void) = ^{
        CGRect newViewStartFrame;
        switch (animation) {
            case AnimatePushFromRight: {
                newViewStartFrame = CGRectOffset(centerFrame, contentView_.bounds.size.width, 0);
                break;
            }
            case AnimatePushFromLeft: {
                newViewStartFrame = CGRectOffset(centerFrame, -contentView_.bounds.size.width, 0);
                break;
            }
            default:
                newViewStartFrame = centerFrame;
                break;
        }

        navbar_.hidden = !isNavbarVisible && !isPrevNavbarVisible;
        if (isNavbarVisible && !isPrevNavbarVisible) {
            navbar_.frame = CGRectMake(newViewStartFrame.origin.x, 0,
                newViewStartFrame.size.width, navbarHeight_);
        }

        newView.frame = newViewStartFrame;
        [self insertSubview:newView belowSubview:navbar_];
        self.userInteractionEnabled = NO;
        animating_ = YES;
    };

    void (^step2)(void) = ^{
        CGRect oldViewFinishFrame;
        switch (animation) {
            case AnimatePushFromRight: {
                oldViewFinishFrame = CGRectOffset(
                    contentView_.frame, -contentView_.bounds.size.width, 0);
                break;
            }
            case AnimatePushFromLeft: {
                oldViewFinishFrame = CGRectOffset(
                    contentView_.frame, contentView_.bounds.size.width, 0);
                break;
            }
            default:
                oldViewFinishFrame = contentView_.frame;
                break;
        }
        if (!isNavbarVisible && isPrevNavbarVisible) {
            navbar_.frame = CGRectMake(oldViewFinishFrame.origin.x, 0,
                oldViewFinishFrame.size.width, navbarHeight_);
        } else {
            navbar_.frame = CGRectMake(centerFrame.origin.x, 0,
                centerFrame.size.width, navbarHeight_);
        }
        newView.frame = centerFrame;
        contentView_.frame = oldViewFinishFrame;

    };

    void (^step3)(void) = ^{
        [contentView_ removeFromSuperview];
        contentView_ = newView;

        self.userInteractionEnabled = YES;
        animating_ = NO;
    };

    [navbar_ setItems:navigationItemStack animated:(animation != AnimateNone)];
    step1();
    [UIView animateWithDuration:(animation != AnimateNone ? animationDuration : 0)
                          delay:0.0
                         options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         step2();

                     }
        completion:^(BOOL finished){
            step3();
        }];
}

来源:https://stackoverflow.com/questions/28982426/the-uiwindows-background-application-is-jumping-at-the-top-of-views-when-i-swit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!