gpt4 book ai didi

ios - UISplitViewController 的主细节 Controller 的动画可见性

转载 作者:行者123 更新时间:2023-11-29 10:53:23 25 4
gpt4 key购买 nike

在我的 UISplitViewController 中,我希望主视图 Controller 仅在处于纵向方向时或当我的详细 View Controller 未显示 Controller 类型 MyFullScreenViewController 时才允许显示。我已经实现了 UISplitViewControllerDelegate 以适本地指示这一点。

-(BOOL)splitViewController:(UISplitViewController *)svc
shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation
{
if (UIInterfaceOrientationIsPortrait(orientation) ||
[[self.navigationController topViewController] isKindOfClass:[MyFullScreenViewController class]])
{
return YES;
}
return NO;
}

但是,UISplitViewController 仅在旋转期间调用委托(delegate)。所以 MyFullScreenViewController 实现了 viewWillAppear:animatedviewWillDisappear:animated

- (void)viewWillAppear:(BOOL)animated
{
[self fakeRotationOfSplitViewController];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self fakeRotationOfSplitViewController];
[super viewWillDisappear:animated];
}
-(void)fakeRotationOfSplitViewController
{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
CGFloat duration = 1.0f;
CGFloat fakeDuration = 0.0f;

[UIView animateWithDuration:duration
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[[self splitViewController] willAnimateRotationToInterfaceOrientation:orientation
duration:fakeDuration];
[[self splitViewController] willRotateToInterfaceOrientation:orientation
duration:fakeDuration];
[[self splitViewController] didRotateFromInterfaceOrientation:orientation];
} completion:^(BOOL finished) {

}];

}

除动画外一切正常。主视图 Controller 在 UINavigationController 对象推送之前和弹出动画之前立即消失并重新出现。

文档不清楚 willRotateToInterfaceOrientation:duration:didRotateFromInterfaceOrientation: 是否应该在动画 block 中调用,但我怀疑它们不应该允许 View Controller 动画它响应消息而变化。但是,如果它们落在动画 block 之外,主视图 Controller 有时会消失。

最佳答案

动画不工作,因为我从未在 didRotateFromInterfaceOrientation: 之后调用 viewWillLayoutSubviews

[UIView animateWithDuration:duration
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[[self splitViewController] willAnimateRotationToInterfaceOrientation:orientation
duration:fakeDuration];
[[self splitViewController] willRotateToInterfaceOrientation:orientation
duration:fakeDuration];
[[self splitViewController] didRotateFromInterfaceOrientation:orientation];
[[self splitViewController] viewWillLayoutSubviews];
[[[self splitViewController] view] layoutSubviews];
} completion:^(BOOL finished) {

}];

关于ios - UISplitViewController 的主细节 Controller 的动画可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19526882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com