0
我想让我的webView正确加载在我设置的CGRect框架中,activityIndicator正在运行。获取UIWebView正确加载CGRect
这种加载正确,当我与[self.view addSubview:webView];
设置,但activityindicator不出现。当我使用webView.delegate = self;
进行设置时,activityindicator确实会出现,但webview在加载时会覆盖整个屏幕。我有一个分段的顶部,然后被掩盖起来。
- (void)viewDidLoad {
[super viewDidLoad];
CGRect webFrame = CGRectMake(0.0, 50.0, 320.0, 318.0);
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activityIndicator];
activityIndicator.frame = CGRectMake(250, 250, 30.0, 30.0);
self.view.center = CGPointMake(160.0f, 190.0f);
activityIndicator.center = self.view.center;
webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
webView.delegate = self;
// [self.view addSubview:webView];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"activity started");
[activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"activity stopped");
[activityIndicator stopAnimating];
self.view = webView;
}
真棒谢谢,工作! – Aaron 2011-03-14 22:10:12