開發(fā)當(dāng)中總會(huì)遇到字體小看不清楚的情況啰劲,我這里做了一個(gè)放大鏡的功能葵蒂。直接上代碼:
- (void)setPointToMagnify:(CGPoint)pointToMagnify
{
_pointToMagnify = pointToMagnify;
CGPoint center = CGPointMake(pointToMagnify.x, self.center.y);
if (pointToMagnify.y > CGRectGetHeight(self.bounds) * 0.5) {
center.y = pointToMagnify.y -? CGRectGetHeight(self.bounds) / 2;
}
self.center = center;
[self.contentLayer setNeedsDisplay];
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGContextTranslateCTM(ctx, self.frame.size.width * 0.5, self.frame.size.height * 0.5);
CGContextScaleCTM(ctx, 1.2, 1.2);
CGContextTranslateCTM(ctx, -1 * self.pointToMagnify.x, -1 * self.pointToMagnify.y);
[self.viewToMagnify.layer renderInContext:ctx];
}