我在这里有一个关于故事板的通用项目.我创建了一个名为MyWindow的UIWindow子类,我需要加载它而不是默认的UIWindow.在故事板之前,我只需要转到XCode中的.XIB文件,然后将主窗口的类更改为MyWindow.但是,我无法找到任何可以在故事板中更改此内容的部分.
有谁知道我能做到这一点?我需要主窗口加载MyWindow,而不是UIWindow.
我正在使用此代码捕获屏幕截图并将其保存到相册中.
-(void)TakeScreenshotAndSaveToPhotoAlbum
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(window.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
Run Code Online (Sandbox Code Playgroud)
但问题是每当截图保存时,我都看不到iPhone的状态栏.相反,底部会出现一个空白区域.如下图所示:

我究竟做错了什么?
我是以编程方式实现列表视图控制器.当我尝试运行该项目时,我收到错误:
2012-11-07 22:46:34.719 myTableViewControl[12021:c07] The app delegate must implement the window property if it wants to use a main storyboard file.
2012-11-07 22:46:34.722 myTableViewControl[12021:c07] -[AppDelegate setWindow:]: unrecognized selector sent to instance 0x7674e70
2012-11-07 22:46:34.723 myTableViewControl[12021:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate setWindow:]: unrecognized selector sent to instance 0x7674e70'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1d194bd 0x10df7ea 0x1c7dcf9 0x1c7d94e 0x1d60 0x107b7 0x10da7 0x11fab 0x23315 0x2424b 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x117da 0x1365c 0x1bd2 …Run Code Online (Sandbox Code Playgroud) uiviewcontroller uinavigationcontroller uiwindow ios appdelegate
一个名为Vesper的应用程序已针对iOS 7进行了更新,并在iOS 7上显示了用户的壁纸.我发现使用UIApplicationIsOpaque键和UIBackgroundStyleLightBlur可以显示用户背景,但不会通过验证.Vesper通过验证并通过Apple.我确实将这个问题上传到开发论坛,但苹果已经把它删除了.
是什么区别makeKeyWindow和makeKeyAndVisible它们是两种方法UIWindow?
什么时候会UIWindow成为keyWindow但不可见?
我已经做了一段时间的iOS开发,但从未使用或看过有人使用Window对象.我试过谷歌搜索但我没有找到任何相关的文章.我知道'UIWindow'对象以及如何从代码中使用它.那么使用Interface Builder的Window对象可以做些什么呢?我何时以及为何选择使用它?
我目前正在修复一个旧应用程序(在iOS 5时代内置)中的问题,其中按钮触摸事件在屏幕底部被忽略.我能够通过创建一个新项目,删除故事板(以及Info plist中的引用)来重新创建这个问题,并在didFinishLaunchingWithOptions中执行以下操作(我知道这不是正确的方法,但这个应用程序我'我正在进行类似的设置)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
self.window.screen = [UIScreen mainScreen];
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor yellowColor];
self.window.rootViewController = vc;
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test setTitle:@"Hey" forState:UIControlStateNormal];
[test setBackgroundColor:[UIColor whiteColor]];
test.frame = CGRectMake(0, 824, 200, 200);
[vc.view addSubview:test];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
一旦我运行这个应用程序,"嘿"按钮只能按下它的上半部分.我感觉它与iOS 7状态栏有关,以及UI现在如何在它下面而不是在它下面.我尝试调整窗口的界限,但这没有用.我已经尝试了各种各样的东西来使这个按钮工作,但唯一有效的是隐藏状态栏.
任何人都有任何线索如何让这个按钮在这种情况下工作?
升级 Xcode 后,我的应用程序的一个关键部分停止工作。
当我的应用程序启动时,我运行一个函数来检查布尔标志并设置正确的 rootViewController。
但是我用来设置它的代码现在已经停止工作了
class func setLoginAsInitialViewContoller(window:UIWindow) {
print("SET LOGIN")
let storyboard = UIStoryboard(name: "Login", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
controller.modalPresentationStyle = .overFullScreen
window.rootViewController = controller
window.makeKeyAndVisible()
}
Run Code Online (Sandbox Code Playgroud)
特别是当应用程序获得倒数第二行时,window.rootViewController = controller它会因libc++abi.dylib: terminating with uncaught exception of type NSException错误而崩溃。
上面的函数在一个被Utilities.swift调用的类中,我正在从我的内部调用该函数AppDelegate.swift,如下所示:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var storyboard: UIStoryboard? = nil
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.isIdleTimerDisabled = true
Utilities.decideInitialViewController(window: self.window!) …Run Code Online (Sandbox Code Playgroud) uiwindow ×10
ios ×8
objective-c ×3
appdelegate ×2
ios7 ×2
swift ×2
xcode ×2
ios13 ×1
iphone ×1
rootview ×1
storyboard ×1
subclass ×1
uikit ×1
uiscreen ×1