iPhone UIWebView - How do you set the zoom level and position?

限于喜欢 提交于 2019-12-09 02:56:29

问题


I'm displaying a series of tiled images in a UIWebView and would like to programmatically set the UIWebview's initial zoom and view location.

How does one go about doing so?


回答1:


NOTE: this answer is from 2009. Please see one of the better solutions for a more civilized age.


Programmatic scrolling of UIScrollView is now a solved problem. I have a detailed discussion of how (and why) UIScrollView zooming works, an example project and ZoomScrollView class that encapsulates the required zooming magic at github.com/andreyvit/ScrollingMadness/.

So probably you should put your images inside UIScrollView like Andy advised.




回答2:


Set attribute scalesPageToFit of UIWebView to YES. Then the webpage is scaled to fit and the user can zoom in and zoom out.




回答3:


You can use this:

for (UIView *subview in webView.subviews) {
    if ([subview isKindOfClass:[UIScrollView class]]) {
        ((UIScrollView *)subview).bounces = NO;
        [((UIScrollView *)subview) setZoomScale:10.5f animated:YES];
    }
}

It may be the solution to your problem.




回答4:


It doesn't look like there's a documented way to do what you want. An alternative that only half solves your problem is using a UIScrollView. You could put UIImageViews inside your UIScrollView and then scroll to any position in the scroll view. This does not allow you to programmatically zoom the view though. If it's something you think should be added to the SDK file a radar: http://bugreport.apple.com/




回答5:


for (id subview in webview)
    if ([[subview class] isSubclassOfClass: [UIScrollView class]])  {
         ((UIScrollView *)subview).bounces = NO;
     }
}

try using this scrollview.



来源:https://stackoverflow.com/questions/674368/iphone-uiwebview-how-do-you-set-the-zoom-level-and-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!