in my xib-based view I have a UIWebView that I need to zoom programmatically.
Since the UIWebView has no own zooming methods I found Max's post that suggested to get the UIWebViews UIScrollView and send the zoom levels to that one.
In my view controller's viewDidLoad method I therefore determined the UIScrollView as follows:
- (void)viewDidLoad {
// set iVars (both are IBOutlets)
iWebView.delegate = self;
iScrollView = [[iWebView subviews] objectAtIndex:0];
iScrollview.minimumZoomScale = 0.2;
iScrollview.maximumZoomScale = 4.0;
iScrollview.zoomScale = iScrollview.minimumZoomScale;
NSLog(@"webViewDidFinishLoad: Current %.3f, Min %.3f, Max %.3f",
iMapScrollView.zoomScale, iMapScrollView.minimumZoomScale, iMapScrollView.maximumZoomScale);
...
}
The UIWebView (by default) contains a 1000x2000px png-file. The NSLog shows
webViewDidFinishLoad: Current 0.200, Min 0.200, Max 4.000
Trouble comes when I try to update the iScrollView.zoomLevel to a new zoom-factor (lets say to 2.4):
- (void)setPositionWithZoom:(float)xPos down:(float)yPos zoomScale:(float)mZoomScale {
iScrollView.zoomScale = mZoomScale;
NSLog(@"setPositionWithZoom: mZoomScale %.3f Current %.3f, Min %.3f, Max %.3f",
mZoomScale , iMapScrollView.zoomScale, iMapScrollView.minimumZoomScale, iMapScrollView.maximumZoomScale);
...
}
The NSLog shows:
setPositionWithZoom: mZoomScale 2.400 mCurrent 1.000 Min 1.000 Max 1.000
So the zoom-level resets to 1 since the min/max zoomlevels have mysteriously fallen back to that value.
I'm flabbergasted, any clues?
EDIT: Further investigation brought me to a touch method that I call from a UIWindow-subclass to forward touch events (implementation of Mithins recipe for grasping touch events with UIWebViews).
It is when this method (myWebViewTouchesEnded) in my viewController gets called that the values are wiped out. I have no idea why.
PATCH: I applied a simple patch to define 2 iVars that i use to set the min/max zoomScales back to my custom values within myWebViewTouchesEnded and evrything works ...