views:

24

answers:

1

This question is similar to this one, but hopefully it will pick up some more interest due to me having tried some stuff.

I am trying to do standard pinch-pan scrolling in a UITextView. My delegate implements UITextViewDelegate and implements this method

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self;
}

[which may in fact be wrong, but returning [[self subviews] objectAtIndex:0] didn't change anything (strangely).

so the pinching stuff works, but when there is a zoom, the UITextView instance loses all notion of allowing me to pan around the content correctly. I've tried to remedy this by including this method

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    CGSize size = self.contentSize;
    size.width *= scale;
    size.height *= scale;
    self.contentSize = size;
}

but all of this guesswork has not gotten me very far (not surprisingly).

Edit: I've done a thing like this, and aside from it blowing up after a bit, it's not exactly what I want. It's the action method of a UIPincheGestureRecognizer:

- (void) doSomething:(id)sender {
    CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
    float size = 12 * factor;
    if (size > 6 && size < 40) {
        self.font = [[UIFont fontWithName:self.font.fontName size:12 * factor] autorelease];
    }
}
A: 

Adding this will add a lot of coherence to the zoom. You could also adjust the text width, which I'm going to look into now:

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
    frameBeforeZooming = self.frame;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    self.frame = frameBeforeZooming;
}

obviously you need a CGRect defined in the header.

Yar