#include "MyWebViewController.h" @implementation MyWebViewController @synthesize webView,startPage; -(id) init { self = [super init]; if( self != nil ) { self.view.autoresizesSubviews = YES; self.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth); self.view.backgroundColor = [UIColor clearColor]; self.view.userInteractionEnabled = NO; // create the web view webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; webView.autoresizesSubviews = NO; webView.scalesPageToFit = YES; webView.delegate = self; webView.hidden = YES; webView.userInteractionEnabled = NO; // add activity indicator activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; activityIndicator.frame = CGRectMake(0.0f, 0.0f, 40.0f, 40.0f); // add view to the stack [self.view addSubview:webView]; [self.view addSubview:activityIndicator]; [activityIndicator startAnimating]; } return self; } -(void) dealloc { [activityIndicator removeFromSuperview]; [activityIndicator release]; activityIndicator = nil; [webView removeFromSuperview]; [webView release]; webView = nil; [super dealloc]; } -(void) setFrame:(CGRect)frame { self.view.frame = frame; webView.frame = frame; activityIndicator.center = CGPointMake(frame.size.width / 2.0f, frame.size.height / 2.0f); } -(void) viewWillAppear:(BOOL)animated { if( startPage != nil ) { // load the html NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:startPage ofType:@"html"]]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; // invalidate start page so we don't load next time [startPage release]; startPage = nil; } [super viewWillAppear:animated]; } -(void) webViewDidStartLoad:(UIWebView*)view { webView.alpha = 0.25f; [activityIndicator startAnimating]; } -(void) webViewDidFinishLoad:(UIWebView*)view { self.view.userInteractionEnabled = YES; webView.userInteractionEnabled = YES; webView.alpha = 1.0f; webView.hidden = NO; self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; self.navigationItem.leftBarButtonItem.enabled = webView.canGoBack; [activityIndicator stopAnimating]; } -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return NO; } @end