macOS开发-知识点总结

  • NSView的背景绘制为图片
    NSImage *backgroundImage = [NSImage imageNamed:@"图片名称"];
    backgroundImage.size = self.bounds.size;
    [backgroundImage lockFocus];
    
    NSColor* backgroundColor = [NSColor colorWithPatternImage:backgroundImage];
    [backgroundColor set];
    NSRectFill(self.bounds);
    
    [backgroundImage unlockFocus];
    
    // draw your new image
    [backgroundImage drawInRect:self.bounds
                       fromRect:NSZeroRect // 绘制整张图片
                      operation:NSCompositeSourceOver
                       fraction:1.0f];
  • 支持NSView的拖拽操作
    -(NSDragOperation)draggingEntered:(id)sender{
    NSPasteboard *pboard = [sender draggingPasteboard];
    
    if([[pboard types] containsObject:NSFilenamesPboardType])
    {
        return NSDragOperationCopy;
    }
        return NSDragOperationNone;
    }
    
      -(BOOL)prepareForDragOperation:(id)sender
    {
        return YES;
    }

    -(BOOL)performDragOperation:(id)sender
    {
        NSArray *filePaths =[[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
        // 利用拖拽文件进行相应操作
    }
    
    -(void)concludeDragOperation:(id)sender
    {
        //拖拽结束
    }
  • 判断NSWindow是否全屏
@interface NSWindow (WFFullScreen)

- (BOOL)isFullScreen;

@end

@implementation NSWindow (BFFullScreen)

- (BOOL)isFullScreen
{
    return (([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask);
}

@end

你可能感兴趣的:(macOS开发-知识点总结)