ios 如何捕获屏幕的特定部分
我想捕捉 iPhone 屏幕的特定部分。我使用了 UIGraphicsBeginImageContextWithOptions,但无法用它捕获屏幕的一部分。 请帮我。
I want to capture a particular portion of iPhone screen. I used UIGraphicsBeginImageContextWithOptions
, but couldn't capture a portion of screen with this.
Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用此代码
you can use this code
您可以使用
UIGraphicsGetImageFromCurrentContext
截取屏幕截图。下面的代码是凭记忆写的,所以可能会出现错误。请自行更正。You can take screen shot using
UIGraphicsGetImageFromCurrentContext
. Wrote below code from memory, so errors possible. Please correct it yourself.这是
UIView
的一个快速扩展,它将捕获整个视图或视图中的一个框架。它考虑了屏幕比例。Here's a swift extension on
UIView
that will either capture the entire view or a frame within the view. It takes into account the screen scale.@Superdev 的答案是正确的,我想添加的是一个小技巧,如果你想捕获父视图并避免子视图(特别是覆盖视图),你可以做的是使这个子视图成为一个属性并使用以下内容
这是一个小技巧,希望有人会发现它有用
the answer by @Superdev is right on spot , what i want to add is a little trick if you want to capture a parent view and avoid subviews ( in particular overlay view ) what you can do is make this subview a property and use the following
its a small trick , hope someone will find it useful
另一种捕获清晰屏幕截图的方法;
Another method to capture clear screenshot;
SWIFT 3.0 Xcode8版本
来自@jDutton 的回答并为我工作。
如果您崩溃并收到以下消息:
请尝试此解决方案
希望能节省您的时间!
SWIFT 3.0 Xcode8 Version
come from @jDutton answer and work for me.
if you crash and get the following message:
try this solution
Hope for saving your time!