问题
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