当我将 UIPinchGestureRecognizer 添加到我的 UITextView 时:
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(didScaleView:)];
[pinchRecognizer setDelegate:self];
[textView addGestureRecognizer:pinchRecognizer];
当放大视图时,视图的大小会增加,并且里面的所有文本也会增加。但是,当我打印 UIFont 或属性文本属性时:
NSLog(@"in didScaleView font %@",view.font);
字体大小始终保持不变(例如,22px)。这是缩放部分:
-(void)didScaleView:(id)sender{
[self.view 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];
}
那么,是什么控制了字体大小的变化(即它是如何变化的)以及在缩放 UITextView 时如何保持不变呢?