UIWebView显示网页没有置顶显示

使用UIWebView显示网页时没有置顶显示,不仅UIWebWiew有这种情况,UITableView也会出现这种情况,处理起来是一样的。如下图所示:


在UIViewController初始化时添加代码:self.automaticallyAdjustsScrollViewInsets = NO;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _webView.frame = self.view.frame;
    self.automaticallyAdjustsScrollViewInsets = NO;
    _webView.delegate = self;
    NSLog(@"url = %@", _url);
    if(_url != nil){
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_url]];
        [_webView loadRequest:request];
    }
}
修改后的效果:

给ViewController设置标题可以用以下代码:self.navigationItem.title = @"框架代码用例"; 或 self.title = @"框架代码用例";

//
//  ViewController.m
//  FrameworkUtils
//
//  Created by dcr on 2017/4/15.
//  Copyright © 2017年. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation ViewController

#pragma mark *******View lifeCycle********

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //通过这个ID得到storyboard中的cell
    NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.textLabel.text = [NSString stringWithFormat:@"UITableViewCell %d", indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self selectItem:indexPath.row];
}

/**
 点击的Item
 **/
- (void)selectItem:(int)row{
    NSLog(@"selectItem row = %d", row);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _tableView.delegate = self;
    _tableView.dataSource = self;
    self.view.backgroundColor = [UIColor whiteColor];
    //设置标题,可用以下两种方法
    self.navigationItem.title = @"框架代码用例";
    //self.title = @"框架代码用例";
    //要把这个设置为false,否则在TableView不会置顶显示
    self.automaticallyAdjustsScrollViewInsets = NO;
    NSLog(@"height = %g, width = %g", SCREEN_SIZE.height, SCREEN_SIZE.width);
    NSLog(@"str = %@", [BackView getString]);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end



猜你喜欢

转载自blog.csdn.net/deng0zhaotai/article/details/70173040