如何手动处理UIPinchGesture?

时间:2014-04-25 07:02:26

标签: ios cocoa-touch uilabel uipinchgesturerecognizer

在我的项目中,我在视图中有一个UILabel。我必须根据识别器的比例值调整字体大小。如果我直接使用变换视图的框架将不会更新,最终我的文本将不会完全可见。

目前,我正在做以下事情,

CGSize recognizerViewNewSize = [[recognizer view] frame].size;
recognizerViewNewSize.width *= [recognizer scale];
recognizerViewNewSize.height *= [recognizer scale];
CGRect recognizerViewFrame = [[recognizer view] frame];
recognizerViewFrame.size = recognizerViewNewSize;
[[recognizer view] setFrame:recognizerViewFrame];

当缩放视图内的标签时,消失了。有什么问题吗? 我已经设置了如下标签,

UILabel *label = [[UILabel alloc] initWithFrame:[self bounds]];
[label setText:labelText];
[label setFont:labelFont];
[label setBackgroundColor:[UIColor redColor]];
[label setNumberOfLines:0];
[label setAdjustsFontSizeToFitWidth:YES];
[label sizeToFit];
[label setTextAlignment:NSTextAlignmentCenter];
[label setAutoresizingMask:(UIViewAutoresizingFlexibleTopMargin |       UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin)];
[label setUserInteractionEnabled:YES];

CGRect labelFrame = [label frame];
CGRect selfFrame = [self frame];
selfFrame.size = labelFrame.size;
[self setFrame:selfFrame];

[self addSubview:label];
[self setLabel:label];

0 个答案:

没有答案