Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标c更改在自定义视图中自动调整NSRect的大小_Objective C_Macos_Cocoa_Nsrect - Fatal编程技术网

Objective c 目标c更改在自定义视图中自动调整NSRect的大小

Objective c 目标c更改在自定义视图中自动调整NSRect的大小,objective-c,macos,cocoa,nsrect,Objective C,Macos,Cocoa,Nsrect,这个标题相当明确地说明了我想做什么。我有一个自定义视图,并在该视图中绘制了一些元素。如何以编程方式更改自动调整大小属性?我环顾四周,找不到任何对我有帮助的东西 目标C: - (void)drawRect:(NSRect)HTMLContent { NSGraphicsContext* gc = [NSGraphicsContext currentContext]; [gc saveGraphicsState]; int height = [[NSScreen mainS

这个标题相当明确地说明了我想做什么。我有一个自定义视图,并在该视图中绘制了一些元素。如何以编程方式更改自动调整大小属性?我环顾四周,找不到任何对我有帮助的东西

目标C:

- (void)drawRect:(NSRect)HTMLContent { 
    NSGraphicsContext* gc = [NSGraphicsContext currentContext];
    [gc saveGraphicsState];
    int height = [[NSScreen mainScreen] frame].size.height;
    int screenwidth = [[NSScreen mainScreen] frame].size.width;
    int emailInnerContentWidth = screenwidth - 510;

    // Horizontal Line
    [[NSColor colorWithCalibratedRed:.8 green:.82 blue:.83 alpha:1] setFill];
    NSBezierPath* drawingPath = [NSBezierPath bezierPathWithRect:NSMakeRect(337, 570, emailInnerContentWidth, 2)];
    [drawingPath fill];

    // Social Icon
    NSRect outrect = NSMakeRect(355, 585, 58, 58);
    [[NSColor lightGrayColor] setStroke];
    [[NSColor colorWithPatternImage:[NSImage imageNamed:@"NoSocialIcon.png"]] setFill];
    NSBezierPath* outcirclePath = [NSBezierPath bezierPath];
    [outcirclePath appendBezierPathWithOvalInRect: outrect];
    [[NSColor lightGrayColor] setStroke];[[NSImage imageNamed:@"NoSocialIcon.png"] drawInRect:outrect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
    [outcirclePath stroke];

    // Restore graphics state
    [gc restoreGraphicsState];
}

我想将这两个形状设置为不受窗口底部变化的影响。我希望它在窗户顶部改变高度时改变。我看了苹果的文档,似乎什么都没用。提前感谢

因此,对于两种形状中的每一种:

[shape setAutoresizingMask:NSViewNotSizable | NSViewMaxXMargin | NSViewMinYMargin];

这会立即使我的应用程序崩溃。还提供了一个警告,
多个名为“setAutosizingMask:”…
如果“shape”是UIView子类,则上述方法应该编译并工作。显然不是。一旦你确定了你的观点,你就可以使用上面的方法来获得正确的答案,谢谢。我没有意识到它必须是一个子类。工作完美!