【问题标题】:Problem with the scrollbar of a UIWebViewUIWebView 的滚动条问题
【发布时间】:2009-11-12 19:44:55
【问题描述】:

我使用 UIWebView 访问网站,当我旋转手机(横向)时,UIWebView 已正确调整大小并且滚动条位于正确的位置(在右边缘......)但是当我访问任何输入字段时填写所需的信息并退出它,UIWebView 滚动条跳到屏幕中间(看起来它回到了 320,纵向屏幕的宽度)。一些有用的信息,这个程序是使用 IB 创建的,有很多出口,我正在考虑以编程方式做(重做)所有事情,因为我不是第一个版本的作者......如果有人在 plz 之前看到过这个,请告诉我。 .

提前致谢!

【问题讨论】:

    标签: iphone objective-c uiwebview scrollbar


    【解决方案1】:

    不要将你的 webview 添加到 self.view 中,只需分配它。简单的事情就像很棒

    wv = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

    [self.view addSubview:wv];

    改为

    self.view = wv;

    【讨论】:

      【解决方案2】:

      在我的测试案例中,我发现我可以通过访问接受输入的网站、调用键盘、关闭键盘(输入或不输入任何输入)来复制这个问题,现在垂直滚动条的显示在纵向位置。

      我在使用和不使用 NIB 的情况下进行了测试,结果是一致的。调用键盘后,当手机(或模拟器)处于横向模式时,垂直滚动条将保持在纵向坐标处。

      我提交了案例#7428286。

      【讨论】:

        【解决方案3】:

        我收到了 Apple 关于可能报告的错误的回复,他们要求提供可以重现问题的示例代码,我发送给他们并在此处发布,以便您也可以进行测试:

        //
        //  viewController.m
        //  TesteWebview
        //
        //  Created by GecanMobile01 on 13/11/09.
        //  Copyright xxx All rights reserved.
        //
        
        #import "viewController.h"
        
        
        @implementation viewController
        
        @synthesize vw, wv;
        
        /*
         // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
        - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
            if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
                // Custom initialization
            }
            return self;
        }
        */
        
        // Implement loadView to create a view hierarchy programmatically, without using a nib.
        - (void)loadView {
            vw = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
            [vw setBackgroundColor:[UIColor grayColor]];
            vw.autoresizesSubviews = YES;
            self.view = vw;
            wv = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        
            [self.view addSubview:wv];
        }
        
        // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
        - (void)viewDidLoad {
            NSURL *urlId = [NSURL URLWithString:@"https://www.google.com"];
            NSURLRequest *theRequest = [NSURLRequest requestWithURL:urlId cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:(NSTimeInterval)10.0];
            [wv loadRequest:theRequest];
            [super viewDidLoad];
        }
        
        // Override to allow orientations other than the default portrait orientation.
        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            // Return YES for supported orientations
            CGRect  cgrWebView;
            BOOL    bChangeOrientation = NO;
            if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
                if (interfaceOrientation == UIInterfaceOrientationPortrait) {
                    cgrWebView = CGRectMake(0.0, 0.0, 320.0, 460.0);
                    bChangeOrientation = YES;
                } else {
                    cgrWebView = CGRectMake(0.0, 0.0, 480.0, 320.0);
                    bChangeOrientation = YES;
                }
                [wv setFrame:cgrWebView];
            }
            return bChangeOrientation;
        }
        
        - (void)didReceiveMemoryWarning {
            // Releases the view if it doesn't have a superview.
            [super didReceiveMemoryWarning];
        
            // Release any cached data, images, etc that aren't in use.
        }
        
        - (void)viewDidUnload {
            // Release any retained subviews of the main view.
            // e.g. self.myOutlet = nil;
        }
        
        
        - (void)dealloc {
            [super dealloc];
        }
        
        
        @end
        

        【讨论】:

          【解决方案4】:

          我在 begreport.apple.com 上报告了一个关于此问题的错误。

          今天(2010 年 4 月 21 日)得到了答案!

          “你好,保罗,

          这是 Bug ID# 7392537 的后续。工程部门认为此问题已在 iPhone OS 4.0 beta 种子 2 中得到解决。(8A248c)

          安装 iPhone OS 4.0b2 软件后,请用您的结果更新此错误报告。

          感谢您的宝贵时间。我们非常感谢您帮助我们发现和隔离错误。 最好的问候,

          帕特里克·柯林斯 苹果开发者连接 全球开发者关系”

          【讨论】:

            【解决方案5】:

            我遇到了同样的问题,但是我在

            中设置了网页视图的框架
            - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            {
            BOOL orientation = NO;
                if(interfaceOrientation == UIInterfaceOrientationPortrait)
                {
                      [webView setFrame:CGRectMake(0, 0, 320, 480)];
                         orientation = YES;
                    return orientation;
                     }else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
                {
                        [webView setFrame:CGRectMake(0, 0, 480, 320)];
                         orientation = YES;
                    return orientation; 
                     }else {
                    orientation = NO;
                    return orientation;
                }
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2011-07-11
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2023-03-23
              • 2011-04-17
              • 1970-01-01
              相关资源
              最近更新 更多