首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Kif截图

使用Kif截图
EN

Stack Overflow用户
提问于 2013-05-02 22:52:27
回答 2查看 1.7K关注 0票数 3

我想在基夫拍个截图。我在kif项目的一个私有类中看到了here,这是可能的,但我很难将其转换为step。有人能帮上忙吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-03 00:41:05

在处理了一下之后,我将这个添加到了我的KIFTestStep.m

代码语言:javascript
复制
 + (id)stepToTakeScreenShotwithName:(NSString *)name;
 {
     NSString *description = [NSString stringWithFormat:@"Take a screenshot saved by the name %@", name];

     return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {

         NSString *outputPath = [NSString stringWithFormat:@"/Users/%@/ScreenShots", NSUserName()];

         NSArray *windows = [[UIApplication sharedApplication] windows];
         if (windows.count == 0) {
             return KIFTestStepResultFailure;
         }

         UIGraphicsBeginImageContext([[windows objectAtIndex:0] bounds].size);
         for (UIWindow *window in windows) {
             [window.layer renderInContext:UIGraphicsGetCurrentContext()];
         }
         UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
         UIGraphicsEndImageContext();

         NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
         NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];

         outputPath = [outputPath stringByExpandingTildeInPath];
         outputPath = [outputPath stringByAppendingPathComponent:[name stringByReplacingOccurrencesOfString:@"/" withString:@"_"]];
         outputPath = [outputPath stringByAppendingString:[timeStampObj stringValue]];
         outputPath = [outputPath stringByAppendingPathExtension:@"png"];
         [UIImagePNGRepresentation(image) writeToFile:outputPath atomically:YES];

         return KIFTestStepResultSuccess;
    }];
 }
票数 2
EN

Stack Overflow用户

发布于 2014-05-20 08:55:46

这是在KIF 3.0.4中添加的。参见here

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16341198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档