我正在实现一个带有轨迹栏的应用程序,它本身就是一个视图,它需要显示最小值和最大值(与栏关联的变量),所以我在它的左上角和右上角添加了两个标签。在没有启用滑块的情况下考虑这样的事情:
我希望能够通过捏合手势缩小或放大此视图,并且以下代码可以正常工作:
-(void) handlePinch:(UIPinchGestureRecognizer *)gr
{
//Shrinking
if(gr.scale < 1)
{
//Get screen width
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
//If the view's would be size is smaller than half the screen's size then don't do anything
//Otherwise shrink the view
if(self.frame.size.width * gr.scale >= screenWidth / 2)
{
//Only scale on x axis, y axes stays the same
self.transform = CGAffineTransformScale(self.transform, gr.scale, 1);
}
}
//Magnifying
else if (gr.scale > 1)
{
//Only scale on x axis, y axes stays the same
self.transform = CGAffineTransformScale(self.transform, gr.scale, 1);
}
//Set scale amount back to 1
gr.scale = 1;
}
问题是当视图缩小时,左上角和右上角的标签也缩小了,它们的字体变小了。由于我只水平缩放视图,这看起来很奇怪。我想设置标签的大小常量并缩小视图内的所有其他内容。
我试图在缩小后用原始标签的大小分配一个新的框架矩形,但没有用。你有什么提示吗?
编辑:设置 minimumFontSize 属性也不起作用(我不尝试 minimumScaleFactor,因为我仍在使用 ios 5 sdk)