我正在尝试对 UITextView 进行捏合效果,以便用户可以根据需要调整其大小。
我面临的问题是,当 textView 增长然后再次缩小时,文本会留下很大的右边距并且看起来很奇怪。每次将 textView 从大调整为小时,右边距都会增加。
以下是我用于捏合效果的代码:
- (void)pinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
initialFrame = textEdit.frame;
}
CGFloat factor = gestureRecognizer.scale;
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
CGRect newframe = CGRectApplyAffineTransform(initialFrame, zt);
[textEdit setFrame:CGRectMake(initialFrame.origin.x, initialFrame.origin.y, newframe.size.width, newframe.size.height)];
}