我在UIScrollView中有一个UITextView,在UITextView中也有一个。我想给UITextView添加一个“变焦技巧”。
我在.h文件中添加了<...UIScrollViewDelegate>。我将其添加到.m文件中。
@synthesize myTextView;
@synthesize scrollView;
- (void)scrollViewDidZoom:(UIScrollView *)sv
{
float zoomScale = sv.zoomScale;
if (zoomScale < 3)
{
if(zoomScale < 0.5)
{
UIFont* myFont = [UIFont systemFontOfSize:12];
myTextView.font = myFont;
}else{
UIFont* myFont = [UIFont systemFontOfSize:(zoomScale * 12)];
myTextView.font = myFont;
}
UIFont* myFont = [UIFont systemFontOfSize:36];
myTextView.font = myFont;
}
}永远不会调用"scrollViewDidZoom“。
我使用接口构建器成功地添加了这些对象。老实说,我有点迷路了。我不知道我应该如何创建出口和代理(具有3级层次结构)。
发布于 2013-04-29 18:50:04
我意识到有一个简单的方法可以用UIPinchGestureRecognizer做到这一点。
- (void)viewDidLoad
{
//...
UIPinchGestureRecognizer *pinchGest = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(changeTextViewFontSize:)];
pinchGest.delegate = self;
[myTextView addGestureRecognizer:pinchGest];
[pinchGest release];
}
- (void)changeTextViewFontSize:(UIPinchGestureRecognizer *)p
{
CGFloat zoomVelocity = [(UIPinchGestureRecognizer *)p velocity];
UIFont *font = self.myTextView.font;
CGFloat pointSize = font.pointSize;
NSString *fontName = font.fontName;
pointSize = ((zoomVelocity > 0) ? 1 : -1) * 1 + pointSize;
if (pointSize < 8) pointSize = 8;
if (pointSize > 32) pointSize = 32;
self.myTextView.font = [UIFont fontWithName:fontName size:pointSize];
}谢谢你Aral Balkan:http://aralbalkan.com/3831/
https://stackoverflow.com/questions/16275789
复制相似问题