我正在尝试将NSView的内容保存为图像,但是,只保存了在scrollview中可见的图像.
以下是视图中加载的实际图像:
.
但这就是我能够保存图像的方式:

有没有办法在NSView中保存整个图像?
这就是我如何保存我的NSView子类:
- (void)save
{
[self lockFocus];
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]];
[self unlockFocus];
NSData* data = [rep representationUsingType:NSPNGFileType properties:nil];
NSString* string = NSHomeDirectory();
NSString* pth1 = [string stringByAppendingPathComponent:@"ttx.png"];
[data writeToFile:pth1 atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)
此方法位于我要保存的视图中.
我有一个简单的顶点着色器:
precision mediump float;
attribute vec4 position;
attribute vec4 color;
varying vec4 f_color;
uniform mat4 projection;
uniform mat4 modelView;
void main(void) {
gl_Position = projection * modelView * position;
f_color = color;
f_texCoord = texCoord;
}
Run Code Online (Sandbox Code Playgroud)
这无法编译,并指出(使用 getShaderInfoLog()):
ERROR: 0:1: 'precision' : syntax error syntax error
Run Code Online (Sandbox Code Playgroud)
如果我删除带有精度说明符的行,它编译得很好。
系统:
OS: Mac OX 10.9.2
GPU: NVIDIA GeForce 320M 256 MB
GLSL Ver.: 1.20
Run Code Online (Sandbox Code Playgroud)
有人帮帮我吧。
我有一个UISplitViewController(是rootViewController)和一个UIViewController,vc1.
我试图从MasterViewController部分向我的分割视图控制器上呈现vc1:
vc1.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:vc1 animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这引发了一个例外:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Application tried to present modally an active
controller <MasterViewController: 0x8c5dd30>.'
Run Code Online (Sandbox Code Playgroud)
......而且崩溃了.
试过这个:
[self.splitViewController presentViewController:vc1 animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这引发了一个例外:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason:'Application tried to present modally an active
controller <UISplitViewController:0x8c7e3a0>.'
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用界面构建器(segues),它可以工作.
如何以编程方式在分割视图控制器上以模态方式(作为页面表或表单)呈现视图控制器?
如何从 zsh 函数返回关联数组?
我试过:
creatAARR() {
declare -A AARR=([k1]=2 [k2]=4)
return $AARR
}
creatAARR
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
creatAARR:return:2: too many arguments
Run Code Online (Sandbox Code Playgroud)
正确的方法是什么?
编辑: 我将输出捕获到标准输出,就像@chepner建议的那样,但新变量的行为似乎不像关联数组:
creatAARR() {
declare -A AARR=([k1]=2 [k2]=4)
echo "$AARR"
}
declare -A VALL
NEW_ARR=$(creatAARR)
echo "$NEW_ARR" # 2 4
echo "k1: $NEW_ARR[k1]" # prints just k1:
return
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
如何在属性中接受方法作为值?就像在视图的 onClick 属性中一样:
<Button android:onClick="onClickMethod"/>
Run Code Online (Sandbox Code Playgroud)
如何定义接受方法的自定义属性?
我知道我们<declare-styleable>在资源中使用,但我们如何让它接受方法?
我有一个可变数组:
NSMutableArray *array;
Run Code Online (Sandbox Code Playgroud)
其中包含许多对象.
我应该使用以下哪一项:
[array replaceObjectAtIndex:10 withObject:anObject];
Run Code Online (Sandbox Code Playgroud)
VS:
array[10] = anObject
Run Code Online (Sandbox Code Playgroud)
在ARC环境中?
编辑:我假设replaceObjectAtIndex:方法将在手动参考计数环境中发送一个释放方法,而直接赋值则不会.如果我使用直接赋值,那么它是否会混淆ARC编译器?