- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的主要 ViewController viewDidLoad 函数中有以下代码
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
nav = [[NavWithAutoRotateViewController alloc] initWithRootViewController:self];
[window addSubview:[nav view]];
[window makeKeyAndVisible];
[[self navigationController] setNavigationBarHidden:YES];
我的 ipad 应用程序当前设置为仅在横向模式下工作,我正在使用这个新窗口显示快速查看文档并允许导航栏提供后退按钮和保存文档选项。主要问题是新的 UIWindow 方向与我的主要应用程序 UIWindow 不匹配。
我在上面有一个名为 NavWithAutoRotateController 的自定义 UINavigationController,这里是该 Controller 的代码。
-(id)init
{
if(self)
{
// _supportedInterfaceOrientatoin = UIInterfaceOrientationMaskLandscape;
// _orientation = UIInterfaceOrientationLandscapeLeft;
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskLandscape;
}
最佳答案
我想我有一个解决方案。问题似乎在于将 UIViewController
分配给额外的 UIWindow
中的 rootViewController
。
如果您只是假设您可以使用主 UIWindow 正在使用的相同 View Controller ,然后将内容添加为新 UIWindow 的 subview ,则存在方向问题。
为了解决这个问题,我做了以下事情:
UIWindow *newWindow = [[UIWindow alloc] initWithFrame: [UIApplication sharedApplication].keyWindow.frame];
newWindow.windowLevel = UIWindowLevelStatusBar+1;
// You can use a view controller instantiated from a xib or storyboard here if you want.
// Just don't use the view controller already set as a UIWindow's rootViewController.
UIViewController *newViewController = [[UIViewController alloc] init];
newWindow.rootViewController = newViewController;
[newWindow makeKeyAndVisible];
// Add something to the new UIWindow. Can use the new UIViewController's view:
[newViewController.view addSubview: myContentView];
// Or could add it as subview of UIWindow: - either works.
[newWindow addSubview: myContentView];
这样做似乎已经解决了围绕旋转的所有奇怪问题。希望这会有所帮助。
关于ios - 如何设置第二个 UIWindow 的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18256381/
我有 2 UIWindows , 当我同时显示 UIWindows最新显示UIWindow总是在显示的第一个之上 UIWindow .每个UIWindow是自己的UIWindow , 所以没有 Sub
我知道这看起来是个大问题,但事实并非如此,所以请不要害怕阅读它。主要是我在解释这些东西是如何工作的。 我有两个 UIWindow在我的应用程序中。第一个是应用程序默认创建的主窗口。第二个叫modalW
我们可以在 native mac 应用程序中使用 NSWindow 和 NSVisualEffectView 轻松创建这种效果,但是我们如何在为 MacCatalyst 构建的应用程序中实现呢? 当然
我已将 Objective-C 文件转换为 Swift,现在转换为: if isCaptured { let colourView = UIView(frame: window.frame)
我有一个 UIWindow 对象,我想将其显示在 Storyboard顶部。我是这样做的 - UIWindow *webWindow = [[UIWindow alloc] initWithFrame
我正在处理一个大约有 7/8 年历史的旧 Xcode 项目,我已将其迁移到 Objective-C 2.0 并支持 ARC。在我参与该项目之前,该项目不支持自动布局(这是在它发布之前)。我已经设法解决
我创建了一个正在加载的 UIWindow,当我开始加载时,我会调用它并 makeKeyAndVisible 。完成后,我 makeKeyAndVisible 我的主 UIWindow。但我的问题是,执
当发送keyboardWillShowNotification时,我可以通过向上移动系统键盘的窗口来将系统键盘移动到选项卡栏上方。然而,当 View Controller 嵌入到导航 Controll
尝试在 IOS 应用程序的关键 UIWindow 上添加一个覆盖窗口。但是,新的覆盖 UIWindow 似乎在任何地方都不可见。 不过,基于 lldb,它似乎已成功添加: (lldb) po UIAp
我有一个自定义的 UIWindow,它是我自己的状态栏,所以我想隐藏状态栏并显示我的状态栏。我有 override var prefersStatusBarHidden: Bool { ret
我有一个应用程序,其中有两个 UIWindow 实例的用例。第一个实例运行所有正常的应用程序交互,但我需要能够在没有用户交互的情况下,无论用户在应用程序中做什么,都能够在所有其他内容之上呈现一个 Vi
我在另一个 UIWIndow 上添加了一个新的 UIWIndow 以显示一个 View ,但它没有显示任何内容,而且屏幕变得有点模糊。这是代码: UIWindow* topWindow = [[UIW
我只是想继承 UIWindow 以便拦截一些通知。除了下面列出的代码,我还进入 MainWindow.xib 并将 UIWindow 对象更新到我的子类。它加载正常,问题是我的选项卡栏上的选项卡没有响
我总是看到对应用程序“窗口”的引用,而且我看到 AppDelegates 通常有一个名为“窗口”的 UIWindow 属性。所以我只是想知道如何感知这个 UIWindow 对象。我看到它是 UIVie
我正在向我的应用添加一个额外的 UIWindow。我的主窗口正确旋转,但我添加的这个附加窗口不旋转。 根据当前设备方向旋转 UIWindow 的最佳方法是什么? 最佳答案 您需要自己为 UIWindo
我认为这很容易,因为 [myWindow resignKeyWindow] 和 [self.window makeKeyAndVisible] 但我想不是……你们知道该怎么做吗? 谢谢:) 最佳答案
在我的应用程序中,我想在主 UIWindow 上创建一个新的 UIWindow,我写如下,但它不起作用。首先,我创建一个 UIWindow 作为主窗口,然后将其设置为键和可见,然后创建一个新的 UIW
我读过的每个视频教程和书籍都会显示以下代码,用于将 UIView 添加到 UIWindow。 [窗口addSubview:self.viewController.view]; 我对上面代码的理解是,将
我的应用程序中需要三个不同的部分:登录屏幕、主屏幕和横向模式下的屏幕,所有这些都完全不同。我看到苹果坚持认为应用程序应该有一个窗口,所以我想问:为此最好使用什么?三扇大 window ,还是风景?层次
我需要查看窗口上的触摸事件,因此我将 UIWindow 子类化以创建 MYWindow 类。我正在重写 sentEvent 函数来接收窗口上的触摸事件,所有这些都工作得很好。为了实现这一目标,我做了以
我是一名优秀的程序员,十分优秀!