我正在开发UIWebView,我想要的是webView不要过度说唱视图。
所以这就是问题所在。我设置了UIWebView,状态栏覆盖在内容上。 我怎么处理这个?我编写的是当我创建UIImage视图时,但当时有导航栏,它运行良好。
我也做了setFrame:CGRectMake(0,20)......但也行不通。为什么[setFrame];方法不起作用?请任何想法。
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
[self.webView setFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];
NSURL *myURL = [NSURL URLWithString:@"http://www.amazon.com"];
NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
[self.webView loadRequest:myURLReq];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
@end
更新:我关闭了自动布局并更改了setFrame:CGRectMake(0, 20 ),现在它们没有重叠。但我想知道为什么我们需要设置它?如果我将状态栏设置为半透明,则有意义。但是我把它设置为默认值,它应该开始在(0,20)状态栏的正下方绘制屏幕。
答案 0 :(得分:3)
试试这个
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
[self.webView setFrame:CGRectMake(0.0, 20.0, self.view.frame.size.width, self.view.frame.size.height)];
NSURL *myURL = [NSURL URLWithString:@"http://www.amazon.com"];
NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
[self.webView loadRequest:myURLReq];
}
您的自动调整大小的掩码应该如下所示。
最终输出:
答案 1 :(得分:1)
在viewDidLoadMethod中添加以下代码:
if( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}