Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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
Iphone 不带状态栏的屏幕截图_Iphone_Ios_Screenshot_Statusbar - Fatal编程技术网

Iphone 不带状态栏的屏幕截图

Iphone 不带状态栏的屏幕截图,iphone,ios,screenshot,statusbar,Iphone,Ios,Screenshot,Statusbar,我正在尝试使用以下代码截图: 但是保存的图像的状态栏变白了,包括信号、时间和电池。如何拍摄包含状态栏内容的屏幕截图? 在截图前隐藏状态栏,如下所示: ([[UIApplication sharedApplication]setStatusBarHidden:是];) (使用iOS 7和自动布局进行测试) 我使用模拟器的“截图”功能,并结合一些条件代码编译。通过取消注释#define,我可以快速切换到启动屏幕的“截图”模式 主要技巧是在打开屏幕的视图控制器出现时隐藏状态栏,但动画很长,因此您有足够

我正在尝试使用以下代码截图:

但是保存的图像的状态栏变白了,包括信号、时间和电池。如何拍摄包含状态栏内容的屏幕截图?

在截图前隐藏状态栏,如下所示:

([[UIApplication sharedApplication]setStatusBarHidden:是];)

(使用iOS 7和自动布局进行测试)

我使用模拟器的“截图”功能,并结合一些条件代码编译。通过取消注释
#define
,我可以快速切换到启动屏幕的“截图”模式

主要技巧是在打开屏幕的
视图控制器
出现时隐藏状态栏,但动画很长,因此您有足够的时间在模拟器中点击屏幕截图命令,该命令会将屏幕截图放在桌面上(如果您愿意,也可以在设备上截图)

使用下面的代码,由于“
uistatusbaranimationne
”,状态栏会立即消失,但“滑出屏幕”会在很长的时间内(下面的代码中为5000.0秒)设置动画。因此,在酒吧开始“移动”垂直大小的20个点中的1个点之前,您有大约5000/20=250秒的时间来拍摄屏幕截图(和一些咖啡)

有关在iOS 7中控制状态栏的更多信息,请在此处查看我的答案和代码:


这是一种不隐藏状态栏的解决方案,只需使用正确的边界,并注意y偏移量应为负值,此处“映射”是填充状态栏下方屏幕的视图: (代码写在ViewController中)


@NitinGohel UIGetScreenImage()是一个私有方法。对不起,伙计,我听不懂你是在问我还是在说@我读了链接。解决方案是使用私有API UIGetScreenImage()Erm,这不是OP想要的。他们想在屏幕截图中包含状态栏的内容。你可以编辑问题标题,因为它看起来确实像你想要的那样。@luyuan查看此链接感谢编辑Anindya,我不知道如何亲自给你发消息,所以我要问我的问题:我总是很难将代码从Xcode复制/粘贴到堆栈溢出-布局很糟糕,但是我使用“插入代码按钮”,然后“粘贴”我的代码。我做错了什么?
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor lightGrayColor];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated{
    UIImageWriteToSavedPhotosAlbum([self screenshot], self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
}

- (UIImage*)screenshot
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        // -renderInContext: renders in the coordinate space of the layer,
        // so we must first apply the layer's geometry to the graphics context
        CGContextSaveGState(context);
        // Center the context around the window's anchor point
        CGContextTranslateCTM(context, [window center].x, [window center].y);
        // Apply the window's transform about the anchor point
        CGContextConcatCTM(context, [window transform]);
        // Offset by the portion of the bounds left of and above the anchor point
        CGContextTranslateCTM(context,
                              -[window bounds].size.width * [[window layer] anchorPoint].x,
                              -[window bounds].size.height * [[window layer] anchorPoint].y);

        // Render the layer hierarchy to the current context
        [[window layer] renderInContext:context];

        // Restore the context
        CGContextRestoreGState(context);
    }
}

// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;
}
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
    #ifdef kTAKE_LAUNCHIMAGE_SCREENSHOT
       return UIStatusBarAnimationNone;
    #else
       return UIStatusBarAnimationSlide;
    #endif
}

- (void)removeStatusBarAnimated
{
    #ifdef kTAKE_LAUNCHIMAGE_SCREENSHOT
        [UIView animateWithDuration:5000.0 animations:^{
            [self setNeedsStatusBarAppearanceUpdate];
        }];
    #else
        [UIView animateWithDuration:2.0 animations:^{
            [self setNeedsStatusBarAppearanceUpdate];
        }];
    #endif
}
UIGraphicsBeginImageContextWithOptions(self.map.bounds.size, NO, [UIScreen mainScreen].scale);
CGRect bounds = CGRectMake(0, -1*(self.view.bounds.size.height-self.map.bounds.size.height), self.map.bounds.size.width, self.map.bounds.size.height);

BOOL success = [ self.view drawViewHierarchyInRect:bounds afterScreenUpdates:YES];

UIImage* image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();