【问题标题】:How to scale a UIWebview properly如何正确缩放 UIWebview
【发布时间】:2015-04-30 19:12:22
【问题描述】:

我有一个 UIWebView,我想使用“比例”因子来调整大小,比如说 0.65。所以我想要做的是乘以这个比例(0.65)的webview的宽度和高度(一开始,等于屏幕的宽度和高度),所以它会变得比屏幕小。有没有办法做到这一点,并确保当我将它旋转到横向时 webview 将保持比例? 这就是我现在正在做的事情。当我只处于纵向模式时它工作正常,但当我将其切换到横向模式时它变得非常混乱。

webview.delegate = self; webview.frame = CGRectMake(0, 0, _adView.frame.size.width * _scale, _adView.frame.size.height * _scale);

webview.center = CGPointMake(_adView.frame.size.width/2, _adView.frame.size.height/2);
webview.bounds = webview.frame;
webview.opaque = NO;
webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

webview.scalesPageToFit = YES;

【问题讨论】:

    标签: objective-c uiwebview scale


    【解决方案1】:

    您是否尝试过在方向更改期间更新您的框架?

       - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
        {
            [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
    
                // Update your views here
    
            } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
            }];
    
            [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      • 2011-08-14
      • 2020-01-21
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      相关资源
      最近更新 更多