使用手势缩放 UIlabel 文本
我正在使用 UIPinchGestureRecognizer 缩放 UILabel
文本。但我无法实现文本的平滑边缘或平滑度。
缩放代码:
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
[pinchRecognizer setDelegate:self];
[holderView addGestureRecognizer:pinchRecognizer];
-(void)scale:(id)sender {
[self bringSubviewToFront:[(UIPinchGestureRecognizer*)sender view]];
if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
lastScale = 1.0;
return;
}
CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);
CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
[[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];
lastScale = [(UIPinchGestureRecognizer*)sender scale];
}
I am scaling UILabel
text using UIPinchGestureRecognizer. But I am not able achieve the smooth edges or smoothness of Text.
code for scaling:
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
[pinchRecognizer setDelegate:self];
[holderView addGestureRecognizer:pinchRecognizer];
-(void)scale:(id)sender {
[self bringSubviewToFront:[(UIPinchGestureRecognizer*)sender view]];
if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
lastScale = 1.0;
return;
}
CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);
CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
[[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];
lastScale = [(UIPinchGestureRecognizer*)sender scale];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在使用转换进行缩放。这会采用原始渲染并将其放大或缩小,但不会改变它。换句话说:“质量”不会改变,只会改变显示的尺寸。相反,您想要的可能是执行以下步骤:
通过更改帧大小,将使用新的大小再次绘制视图,这将比放大较小的视图获得更好的质量。
我不确定在捏合过程中是否可以更改框架(这可能会干扰识别器),也许您需要应用您现在正在执行的转换,并在手势时执行更改框架大小方法完成后,捏合完成后可以获得高质量版本(有时您可以在滚动视图中看到类似的图案)。
The problem is that you're scaling using a transformation. That takes the original rendering and scales it up or down, but doesn't change it. In other words: the "quality" doesn't change, only at what size you're displaying it. What you want instead is probably to do the following steps:
By changing the frame size the view is drawn again with the new size which will result in better quality than scaling up a smaller view.
I'm not sure whether changing the frame is possible during pinching (it might be messing with the recognizer), maybe you need to apply the transformation you're doing right now and do the change-frame-size-method when the gesture is done to get a high quality version after the pinch is finished (you can see a similar pattern sometimes with scroll views).