iOS截屏功能
ios 功能 截屏
2023-09-27 14:28:40 时间
代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//初始化界面
[self addView];
}
#pragma -mark -functions
//初始化界面
-(void)addView
{
UIImage *image = [self screenshot:UIDeviceOrientationPortrait
isOpaque:YES
usePresentationLayer:YES];
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
imageView.backgroundColor=[UIColor redColor];
imageView.image=image;
[self.view addSubview:imageView];
}
//截屏功能
- (UIImage *)screenshot:(UIDeviceOrientation)orientation isOpaque:(BOOL)isOpaque usePresentationLayer:(BOOL)usePresentationLayer
{
CGSize size;
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
size = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
} else {
size = CGSizeMake(self.view.frame.size.height, self.view.frame.size.width);
}
UIGraphicsBeginImageContextWithOptions(size, isOpaque, 0.0);
if (usePresentationLayer) {
[self.view.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
} else {
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
相关文章
- iOS exit(),abort(),assert()函数区别
- iOS开发点滴 - 关闭键盘
- 【干货】iOS 11 短信拦截功能初探
- 《iOS 8开发指南(第2版)》——第1章,第1.7节常用的第三方工具
- iOS线程之——NSCondition
- iOS中的界面多选功能--(UICollectionView)
- iOS绘图教程
- iOS蓝牙BLE4.0通信功能
- iOS 16 SwiftUI 4 新功能之 SFSymbol VariableValue 实现可变着色
- iOS 开源完整项目之从视频高质量提取照片(含源码)
- iOS网络缓存的系统实现是一个烂尾工程
- iOS的图片:解码(CPU)与内存(缓存)
- IOS Html富文本渲染方式:DTCoreText、WKWebView、UIWebView的内存占用对比
- iOS动画的要素:CALayer维护数据模型和图片,沟通了CPU和GPU--视图中与图形绘制相关的功能
- Clubhouse的iOS开发工程师在Clubhosue将干哪些工作
- iOS教你轻松打造瀑布流Layout
- iOS-自定义导航栏后侧滑返回功能失效
- 解决uniapp ios播放本地视频不显示controls的问题、uni-app video开始播放如何设置默认全屏
- iOS 10支持图片搜索?带你认识下安防领域的检索功能!
- IOS开发之支付功能概述
- iOS多线程