简体   繁体   English

iPhone UIWebView - 如何设置缩放级别和 position?

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

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.我在 UIWebView 中显示一系列平铺图像,并希望以编程方式设置 UIWebview 的初始缩放和查看位置。

How does one go about doing so? go 是怎么做到的呢?

Set attribute scalesPageToFit of UIWebView to YES.将 UIWebView 的属性 scalesPageToFit 设置为 YES。 Then the webpage is scaled to fit and the user can zoom in and zoom out.然后网页被缩放以适应用户可以放大和缩小。

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.它可能是您问题的解决方案。

NOTE: this answer is from 2009. Please see one of the better solutions for a more civilized age.注意:此答案来自 2009 年。请参阅更文明时代的更好解决方案之一。


Programmatic scrolling of UIScrollView is now a solved problem. UIScrollView 的编程滚动现在是一个已解决的问题。 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/ .我详细讨论了 UIScrollView 缩放的工作原理、示例项目和 ZoomScrollView class,它封装了ZBF215181B5140522137B3D4F6B7354dreyness4AZ.com/

So probably you should put your images inside UIScrollView like Andy advised.所以可能你应该像安迪建议的那样把你的图像放在 UIScrollView 中。

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

try using this scrollview.尝试使用此滚动视图。

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.只能解决一半问题的替代方法是使用 UIScrollView。 You could put UIImageViews inside your UIScrollView and then scroll to any position in the scroll view.您可以将 UIImageViews 放在 UIScrollView 中,然后滚动到滚动视图中的任何 position。 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/如果您认为应该将其添加到 SDK 文件中,请使用雷达: http://bugreport.apple.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM