我正在使用UIView
转换来在ViewControllers
之间转换。转换完成后会出现明显的子视图错位,然后在短暂延迟后得到纠正。
我录制了一段简短的视频片段来说明这个问题:
https://drive.google.com/file/d/0B-iP0P7UfFj0dEE3OVN5Q3BTbUU/edit?usp=sharing
请注意滑块,以及按钮标题的潜在外观
这是进行转换的辅助方法:
#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];
}
}
我只是打电话来进行转换
#define VC_MORE @"MoreViewController" //story board identifier
- (IBAction)setting:(id)sender {
[Helper toVCWithIdentifier:VC_MORE transition:TransitionRootToSub];
}
在MoreViewController
中,我将其称为回到主
#define VC_MAIN @"MainViewController"
- (IBAction)back:(id)sender {
[Helper toVCWithIdentifier:VC_MAIN transition:TransitionSubToRoot];
}
答案 0 :(得分:1)
在-toVCWithIdentifier
方法中尝试此操作
(只是把它放在过渡之外)
[Helper window].rootViewController = [Helper viewControllerWithStoryboardID:identifier];
[UIView transitionWithView:[Helper window] duration:DURATION_TRANSITION options:option animations:^{
} completion:nil];