截屏

作者: Gxpzy | 来源:发表于2016-12-12 17:04 被阅读34次

关于截屏今天在这里总结一下

  • 如何截取状态栏
  • 如何截取除状态栏之外的屏幕
  • 如何截取整个屏幕

截取状态栏

很多人想截取整个屏幕,但是总是截取不到状态栏,那么我们就先来看看如何只截取状态栏,我把它分为两个步骤

  1. 获取到状态栏

    UIApplication * app = [UIApplication sharedApplication];
    UIView *statusBar = [app valueForKey:@"_statusBar"];
    
  2. 截取

    UIGraphicsBeginImageContext(statusBar.frame.size);
    [statusBar drawViewHierarchyInRect:statusBarview.bounds afterScreenUpdates:YES];
    
    UIImage *image = [UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    

截取除状态栏之外的屏幕

截取

```
- (UIImage *)snapshot:(UIView *)view

{

    UIGraphicsBeginImageContext(view.frame.size);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;
}
这里只需传入`self.view`就可以了
## 截取整个屏幕
有了前面两个,我想第三个问题就迎刃而解了吧,这里给个提示,可以分别截取后把两张图片合成一个。

相关文章

网友评论

    本文标题:截屏

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