首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITextView in UIScrollView in UIView : IBOutlet Hierarchy?

UITextView in UIScrollView in UIView : IBOutlet Hierarchy?
EN

Stack Overflow用户
提问于 2013-04-29 17:56:02
回答 1查看 96关注 0票数 1

我在UIScrollView中有一个UITextView,在UITextView中也有一个。我想给UITextView添加一个“变焦技巧”。

我在.h文件中添加了<...UIScrollViewDelegate>。我将其添加到.m文件中。

代码语言:javascript
复制
@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级层次结构)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-29 18:50:04

我意识到有一个简单的方法可以用UIPinchGestureRecognizer做到这一点。

代码语言:javascript
复制
- (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/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16275789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档