NSSavePanel在优胜美地崩溃 [英] NSSavePanel crashes on Yosemite

查看:127
本文介绍了NSSavePanel在优胜美地崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NSSavePanel 保存图像.

我使用了 IKSaveOption 添加到NSSavePanel. 当保存"面板尝试打开工作表窗口时,它崩溃,提示-

I have used IKSaveOption which gets added to the NSSavePanel. When save panel tries to open the sheet for window it crashes saying -

***-[IKSaveOptionsContainer _didChangeHostsAutolayoutEngineTo:],/SourceCache/AppKit/AppKit-1343.14/Layout.subproj/NSView_Layout.m:577中的断言失败 -如果_didChangeHostsAutolayoutEngineTo:YES,应将自动调整大小的掩码转换为约束.

*** Assertion failure in -[IKSaveOptionsContainer _didChangeHostsAutolayoutEngineTo:], /SourceCache/AppKit/AppKit-1343.14/Layout.subproj/NSView_Layout.m:577 - Should translate autoresizing mask into constraints if _didChangeHostsAutolayoutEngineTo:YES.

我正在遵循以下代码:

NSSavePanel *savePanel = [NSSavePanel savePanel];
    [savePanel setDirectoryURL:[NSURL URLWithString:NSHomeDirectory()]];
    [savePanel setDelegate:self];
    [savePanel setPrompt:NSLocalizedString(@"save",nil)];
    [savePanel setAllowedFileTypes:[NSArray  arrayWithObjects:@"png",@"jpeg",nil]];
      IKSaveOptions * opt = [[IKSaveOptions alloc] initWithImageProperties:nil
                                                          imageUTType:(NSString *)kUTTypePNG];
    [opt addSaveOptionsAccessoryViewToSavePanel:savePanel];
    [savePanel setExtensionHidden:NO];

   [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result){.....
}

此代码可在Maverick中使用,但不能在优胜美地上使用.新的OS API是否有任何布局更改?

This code works in Maverick, but not on Yosemite. Are there any layout changes in the new OS API?

推荐答案

Update2:该解决方案很简单.

Update2: The solution turns out to be simple.

[self.saveOptions addSaveOptionsAccessoryViewToSavePanel:savePanel];
savePanel.accessoryView.translatesAutoresizingMaskIntoConstraints = YES;

更新:以下解决方法不会更改文件名的扩展名,并且根据您保存文件的方式,可能不会接受新格式的请求.

Update: The below workaround does not change the filename's extension and depending on how you save the file, the new format request may not be honored.

我找到了一种解决方法,并向Apple(20595916)提交了一个错误.解决方法不是很好,因为超级视图的大小可能不足,并且会裁剪图像选项的控件.

I found a workaround, and I filed a bug with Apple (20595916). The workaround isn't great because the superview's size might be inadequate and clip the controls for the image options.

NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 400, 200)];
view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
savePanel.accessoryView = view;

[self.saveOptions addSaveOptionsToView:view];

这篇关于NSSavePanel在优胜美地崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆