macOS開發(fā)-知識點總結(jié)

  • 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<NSDraggingInfo>)sender{
    NSPasteboard *pboard = [sender draggingPasteboard];
    
    if([[pboard types] containsObject:NSFilenamesPboardType])
    {
        return NSDragOperationCopy;
    }
        return NSDragOperationNone;
    }
    
      -(BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender
    {
        return YES;
    }

    -(BOOL)performDragOperation:(id<NSDraggingInfo>)sender
    {
        NSArray *filePaths =[[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
        // 利用拖拽文件進行相應(yīng)操作
    }
    
    -(void)concludeDragOperation:(id<NSDraggingInfo>)sender
    {
        //拖拽結(jié)束
    }
  • 判斷NSWindow是否全屏
@interface NSWindow (WFFullScreen)

- (BOOL)isFullScreen;

@end

@implementation NSWindow (BFFullScreen)

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

@end
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容