0

I have a problem and not solve! need a "pinch" to zoom in the text of webView, someone help me?

I'm doing well, correct?

CODE:

- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {

    if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        // Reset the last scale, necessary if there are multiple objects with different scales
        lastScale = [gestureRecognizer scale];
    }

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
        [gestureRecognizer state] == UIGestureRecognizerStateChanged) {


        float newScale = [gestureRecognizer scale]; // new scale is in the range (0-1)
        if(newScale > 1.90 && newScale < 14){
            zoomValue = newScale * 10;
            NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('div')[0].style.webkitTextSizeAdjust= '%f%%'",(zoomValue * 2)];
            [self.webView stringByEvaluatingJavaScriptFromString:jsString];
            newScale=zoomValue * 2;
        } else if(newScale > 4){
             NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('div')[0].style.webkitTextSizeAdjust= '%f%%'",(200.0)];
            newScale = 200.0;
        } else if(newScale < 2.317240) {
             NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('div')[0].style.webkitTextSizeAdjust= '%f%%'",(95.0)];
            newScale = 95.0;
        }

        lastScale = [gestureRecognizer scale]; 
    }
}

It works, but want to improve!

  • Hi Felipe, welcome to Stack Overflow! Since you're basically asking for a code review of working code, I suggest you move this to the codereview.stackexchange.com site instead. Stack Overflow is more geared to finding answers to very specific problems or errors. – Dan Bowling Jan 21 '16 at 18:39
  • I need to learn how to do, if someone could help me! I showed the example – Felipe Xavier Jan 21 '16 at 18:41
  • Then I suggest that you update the "It works, but want to improve!" to hone your question a bit more. Sorry I can't help more, as I'm not an objective C programmer. – Dan Bowling Jan 21 '16 at 18:43

0 Answers0