- (void)viewDidLoad
{
[super viewDidLoad];
NSString * urlString = @"......";
[_postWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
_postWebView.delegate = self;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
[self.postProgress setHidden:NO];
[self.postProgress startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[self.postProgress stopAnimating];
[self.postProgress setHidden:YES];
}
NSURL *mobileurl = [NSURL URLWithString:@"http://campusbus.ntu.edu.sg/ntubus/index.php/m/main"];
NSError* error = nil;
NSString* text = [NSString stringWithContentsOfURL:mobileurl encoding:NSASCIIStringEncoding error:&error];
if( text )
{
NSLog(@"Text=%@", text);
}
else
{
NSLog(@"Error = %@", error);
}
this is because "automatic bring-field-into-view scrolling when you navigate around a web form"
For my case, I added listener to keyboard show and hide, during keyboard will show/hide set uiwebview.scrollview bounds to webview.bounds
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (self.duringWillKeyboard)
scrollView.bounds = self.webView.bounds;
after some debugging I found webview.frame and webview.scrollview.frame wont change, the only thing change is webview.scrollview.contentoffset.y
so execute javascript code after scrolling:
- (void)stoppedScrolling
{
float newHeight = _htmlBodyHeight + self.webView.scrollView.contentOffset.y;
NSLog(@"old height is %f, new height is %f", _htmlBodyHeight, newHeight);
NSString *jsCode = [NSString stringWithFormat:@"document.body.style.height = '%fpx'",newHeight];// @"document.body.style.height = '1000px'";
[self.webView stringByEvaluatingJavaScriptFromString:jsCode];
}
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)]; to appDelegate didFinishLaunchingWithOptions