gpt4 book ai didi

ios - rootViewController 已设置但显示方向不正确

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:49:37 25 4
gpt4 key购买 nike

我的情况和this question很相似.我有一个通用的应用程序,其中 iPhone 为纵向,iPad 为横向,我使用 appDelegate.window.rootViewController = newScreen; 在所有主屏幕之间切换。 iPhone 应用程序完美运行。 iPad 应用程序有时会以纵向而不是横向显示屏幕。下面是一些示例转换代码:

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ViewController* v = nil;
if (IS_IPAD()) {
v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
}else{
v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}
[appDelegate.window setRootViewController:(UIViewController*)v];

我也从 this other question 尝试过这个:

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ViewController* v = nil;
if (IS_IPAD()) {
v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
}else{
v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}

[UIView
transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[appDelegate.window setRootViewController:(UIViewController*)v];
[UIView setAnimationsEnabled:oldState];
}
completion:nil];

但没有什么能解决它。

还尝试使用 [appDelegate.window makeKeyAndVisable] 和 [appDelegate.window makeKeyWindow],希望这会“冲击”它以做出正确的方向。

最佳答案

我知道了!

这是我的转换 block 的样子。我所做的关键事情是从 CALayer 复制变换(执行实际旋转的东西)。请注意,您必须包括 Quartz 框架和 #import <QuartzCore/QuartzCore.h>在文件的顶部。

[UIView transitionWithView:self.window 
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
target.view.layer.transform = window.rootViewController.view.layer.transform;
window.rootViewController = target;
[UIView setAnimationsEnabled:oldState];
} completion:nil];

关于ios - rootViewController 已设置但显示方向不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11217123/

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