我想实现一个放大镜,就像长按 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 中获取我需要的部分?
谢谢