简体   繁体   中英

iOS UIView Transition subview misplacement for a short while

I am using UIView transition to transit between ViewControllers . There is a noticeable subview misplacement after the transition is done, which then gets corrected after a short delay.

I have recorded a short video clip to illustrate this problem:

https://drive.google.com/file/d/0B-iP0P7UfFj0dEE3OVN5Q3BTbUU/edit?usp=sharing

Please pay attention to the slider, and also the latent appearance of the titles of buttons

This is a helper method to do the transition:

#define DURATION_TRANSITION 0.5

+ (void)toVCWithIdentifier:(NSString *)identifier transition:(Transition)transition {
    UIViewAnimationOptions option;
    if (transition == TransitionRootToSub) {
        option = UIViewAnimationOptionTransitionCurlUp;
    }
    else if (transition == TransitionSubToRoot) {
        option = UIViewAnimationOptionTransitionCurlDown;
    }
    else if (transition == TransitionPresent) {
        option = UIViewAnimationOptionTransitionFlipFromBottom;
    }
    else if (transition == TransitionDismiss) {
        option = UIViewAnimationOptionTransitionFlipFromTop;
    }
    else {
        option = UIViewAnimationOptionTransitionCrossDissolve;
    }
    [UIView transitionWithView:[Helper window] duration:DURATION_TRANSITION options:option animations:^{
        [Helper window].rootViewController = [Helper viewControllerWithStoryboardID:identifier];
    } completion:nil];

}



+ (UIViewController *)viewControllerWithStoryboardID:(NSString *)storyboardID {
    if (IS_IPHONE) {
        return [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:storyboardID];
    }
    else {
        return [[UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil] instantiateViewControllerWithIdentifier:storyboardID];
    }

}

And I simply call to make the transition

#define VC_MORE @"MoreViewController" //story board identifier

- (IBAction)setting:(id)sender {
    [Helper toVCWithIdentifier:VC_MORE transition:TransitionRootToSub];
}

And in MoreViewController , I call this to go back to main

#define VC_MAIN @"MainViewController"

- (IBAction)back:(id)sender {
    [Helper toVCWithIdentifier:VC_MAIN transition:TransitionSubToRoot];
}

Try this in your -toVCWithIdentifier method (Just put it outside the transition)

[Helper window].rootViewController = [Helper viewControllerWithStoryboardID:identifier];
[UIView transitionWithView:[Helper window] duration:DURATION_TRANSITION options:option animations:^{

} completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM