美文网首页
MacOS 开发, 视图的截屏

MacOS 开发, 视图的截屏

作者: 包砸豆沙馅 | 来源:发表于2020-02-26 20:06 被阅读0次
    
    - (void)makeScreenPicture {
    
        [self.view lockFocus];
    
        NSData * data = [self.view dataWithPDFInsideRect:self.view.bounds];
    
        NSData* convertData = [[NSImage alloc]initWithData:data].TIFFRepresentation;
    
        [self.view unlockFocus];
    
        NSFileManager * fileMgr = [NSFileManager defaultManager];
    
        NSString * path = @"/Users/yourName/Desktop/mytest.png";
    
        [fileMgr createFileAtPath:pathcontents:convertData attributes:nil];
    
        NSURL* fileUrl = [NSURL fileURLWithPath:path];
    
    //截屏之后 在finder中打开.
    
        [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[fileUrl]];
    
    }
    
    

    相关文章

      网友评论

          本文标题:MacOS 开发, 视图的截屏

          本文链接:https://www.haomeiwen.com/subject/tacwchtx.html