使用 CALayer 实现放大镜效果

发布于 2024-09-10 17:18:43 字数 725 浏览 1 评论 0原文

我想实现一个与长按 UITextView 时显示的放大镜完全相同的放大镜。

我从这里得到了这个想法: iPhone,重现放大镜效果

但是我只使用 CALayers 而不是 UIViews,因此我没有可写入的 drawRect 方法。我想知道我应该在哪里写这个? 在 display 方法中?或 drawInContext: 方法?

如何有效地栅格原始视图中的所有图层? (视图被放大)这真的是一个好主意吗:

UIGraphicsBeginImageContext(magnifyView.bounds.size); //magnifyView is the view to be magnified
[magnifyView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
_cache = UIGraphicsGetImageFromCurrentImageContext(); //_cache is an UIImage
UIGraphicsEndImageContext();

然后从这个 UIImage 的 CGImageRef 中获取我需要的部分?

谢谢

I want to implement a magnifier exactly like the one is shown when an UITextView is long pressed.

I got the idea from here: iPhone, reproduce the magnifier effect

But I am working only with CALayers not UIViews, hence I don't have a drawRect method to write in. I wonder where should I write this?
inside display method? or drawInContext: method?

How can I efficiently raster all the layers from the original view? (the view to be magnified) is it really a good idea to do:

UIGraphicsBeginImageContext(magnifyView.bounds.size); //magnifyView is the view to be magnified
[magnifyView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
_cache = UIGraphicsGetImageFromCurrentImageContext(); //_cache is an UIImage
UIGraphicsEndImageContext();

and then get the portion I need from this UIImage's CGImageRef?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文