注意:这可能是添加到根视图控制器时Subview不自动调整大小的副本
我有一个iPad应用程序在其主窗口中切换不同的视图.视图切换代码如下所示:
- (void)switchToViewController:(UIViewController*)viewController {
if (currentViewController != viewController) {
[currentViewController.view removeFromSuperview];
currentViewController = viewController;
[window addSubview:viewController.view];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当新视图(UISplitView)以横向方向显示时,其大小不足以填充整个窗口.右边有一个空的黑色大空间.看起来视图只有768像素宽,而不是景观窗口的1024像素宽度.
如果我将设备旋转为纵向然后返回横向,则视图会自行调整大小.
如果设备处于纵向,一切正常.如果它是我展示的第一个视图,UISplitView也会正确调整大小.如果我在横向显示另一个视图后切换到它,则只会出现此问题.
那么,是否有某种方法可以强制iPhone OS在将视图添加到窗口后调整视图大小?
我已经打过电话sizeToFit,和setNeedsLayout.我也尝试将视图设置为bounds窗口bounds,我尝试将其设置frame为匹配上一个视图的帧.
嗨,您好,
我正在尝试使用UIScreen在iPad上使用VGA加密狗来驱动单独的屏幕.
这是我在根视图控制器的viewDidLoad中得到的:
//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);
//Now, if there's an external screen, we need to find its modes, itereate through them and find the highest one. Once we have that mode, break out, and set the UIWindow.
if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected to the device
{
CGSize max;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] …Run Code Online (Sandbox Code Playgroud) 我的应用程序使用2个UIWindows.第一个显示的TabBar控制器带有ViewControllers,只能旋转到纵向方向.到这里一切都很好.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (UIInterfaceOrientationIsPortrait(interfaceOrientation));
}
Run Code Online (Sandbox Code Playgroud)
在另一个窗口,我有一个旋转到所有方向的UIViewController.
问题是当我显示第二个窗口时
[secondWindow makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
然后回到第一个
[firstWindow makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
状态栏将旋转到所有方向,并且不会触发事件shouldAutorotateToInterfaceOrientation.我该如何解决这个问题?
我正试图为我的应用程序制作一个"黑暗模式",我想以一种非常简单的方式做到这一点.有没有办法应用过滤器或在我的其他视图上创建另一个视图,使它们看起来倒置 - 很像iOS 3.2+上的"辅助功能"?我知道Core Image过滤器在iPhone上不起作用,但这对我来说并不是什么大问题 - 只要有一种方法可以应用不同类型的过滤器.
这在iPhone上可行吗?Apple如何做到这一点?
我有一个应用程序,比如'MyApp',默认情况下,只要应用程序启动,它就会加载视图控制器'MyAppViewController'.后来,我在项目中添加了一个新的视图控制器'NewViewControler'.
我现在希望'NewViewController'成为我的默认视图控制器,它在应用程序启动时加载.
请告诉我在项目中需要做出哪些改变才能实现这一目标.
我正在尝试在iPad应用程序的基础上添加一个新窗口,但我无法弄清楚为什么它总是呈现为全屏.我正在使用此代码:
UIWindow *window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
[window setFrame:CGRectMake(0, 0, 20, 20)];
ArrowController *controller = [[ArrowController alloc]initWithNibName:@"ArrowController" bundle:nil];
[window setRootViewController:controller];
[window setHidden:NO];
[controller release];
Run Code Online (Sandbox Code Playgroud)
无论我在框架上放置什么尺寸,我都会看到一个全屏大小的窗口.请指教,谢谢.
我正在考虑将AirPlay功能添加到我的一个ViewControllers中.View Controller只显示一个UIWebView.我想要做的是添加一个按钮,将此内容镜像到Apple TV.我知道系统范围的镜像可以完成,但它不会填满整个屏幕,周围都是黑条.我一直在网上搜索,但我发现的大部分内容都是从iOS 5回来并且已经过时了.有人能指出我的教程或插入库的方向会有所帮助吗?我只需要在Apple TV上将一个视图的内容镜像为全屏.
到目前为止,这是我所做的,但我相信它只会创建第二个窗口,而不会在其上放置任何内容.
在AppDelegate中,我为它创建了一个属性:
@property (nonatomic, retain) UIWindow *secondWindow;
Run Code Online (Sandbox Code Playgroud)
在AppDelegate的didFinish方法中,我运行:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
然后在AppDelegate中我有:
- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification
{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
if (!self.secondWindow)
{
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = newScreen;
// Set the initial UI for the window.
}
}
- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification
{
if (self.secondWindow)
{
// Hide and then delete the window.
self.secondWindow.hidden = YES;
self.secondWindow = …Run Code Online (Sandbox Code Playgroud) 这是一个简单的单视图控制器应用程序:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor greenColor];
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)
iOS 8中的输出是如此不同.


这与iOS 8与iOS 7的UIWindow界限有什么关系.我如何获得iOS 7的行为?
我想实现一个单独的ErrorHandler类,它显示某些事件的错误消息.应该从不同的其他类调用此类的行为.发生错误时,它将具有UIAlertView输出.此AlertView的显示应始终位于顶部.因此无论从何处抛出Error,最顶层的viewController都应该显示AlertMessage(例如,当异步后台进程失败时,我想要一条错误消息,无论前景中显示什么View).
我找到了几个似乎可以解决我的问题的要点(见下面的代码).但是调用UIApplication.sharedApplication().keyWindow?.visibleViewController()确实会返回一个零值.
从要点扩展
extension UIWindow {
func visibleViewController() -> UIViewController? {
if let rootViewController: UIViewController = self.rootViewController {
return UIWindow.getVisibleViewControllerFrom(rootViewController)
}
return nil
}
class func getVisibleViewControllerFrom(vc:UIViewController) -> UIViewController {
if vc.isKindOfClass(UINavigationController.self) {
let navigationController = vc as! UINavigationController
return UIWindow.getVisibleViewControllerFrom( navigationController.visibleViewController)
} else if vc.isKindOfClass(UITabBarController.self) {
let tabBarController = vc as! UITabBarController
return UIWindow.getVisibleViewControllerFrom(tabBarController.selectedViewController!)
} else {
if let presentedViewController = vc.presentedViewController {
return UIWindow.getVisibleViewControllerFrom(presentedViewController.presentedViewController!)
} else {
return vc;
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Xcode 11 beta 6和iOS 13 beta 8构建我的应用程序,但是一旦它开始运行,它将引发此错误:
由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“在UIApplication上名为-statusBar或-statusBarWindow的应用程序:由于不再有状态栏或状态栏窗口,因此必须更改此代码。而是在窗口场景上使用statusBarManager对象。'
什么是窗口场景,如何使用statusBarManager?
而且我不确定这是否相关,但是我没有使用any SwiftUI。
uiwindow ×10
iphone ×5
ios ×4
ipad ×2
swift ×2
uiview ×2
airplay ×1
apple-tv ×1
cocoa-touch ×1
gnu-screen ×1
ios13 ×1
ios4 ×1
ios7.1 ×1
ios8 ×1
objective-c ×1
rotation ×1
uialertview ×1
uikit ×1
uistatusbar ×1
vga ×1