1

UITextView 内の UIScrollView 内に 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」が呼び出されることはありません。

これらのオブジェクトを Interface Builder で正常に追加しました。正直なところ、私は少し迷っています。アウトレットとデリゲート (3 レベルの階層) を作成する方法がわかりません。

4

1 に答える 1

1

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];
}

ありがとうアラルバルカン : http://aralbalkan.com/3831/

于 2013-04-29T10:50:04.417 に答える