I have two view controllers inside a navigation controller. The 1st view controller has a menu with a button. Pressing this button moves to the 2nd view controller and loads a html string into a UIWebView. Nothing else is being loaded to the webview, just a simple NSString with html code in it. Essentially I'm making a flip card (two views) with the webview as a subview of one of the uiviews.
Here's the code:
containerView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)];
[self.view addSubview:containerView];
frontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)];
frontView.layer.cornerRadius = 10;
frontView.layer.masksToBounds = YES;
[frontView setBackgroundColor:[UIColor whiteColor]];
backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)];
backView.layer.cornerRadius = 10;
backView.layer.masksToBounds = YES;
[backView setBackgroundColor:[UIColor yellowColor]];
[containerView addSubview:frontView];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)];
webView.scalesPageToFit = YES;
webView.userInteractionEnabled = NO;
NSString *htmlString = @"<head><meta name='viewport' content='width=device-width;'><style type='text/css'>html,body {margin: 0;padding: 0;width: 100%;height: 100%;}html {display: table;}body {display: table-cell;vertical-align: middle;padding: 20px;text-align: center;-webkit-text-size-adjust: none;}</style></head><ruby>金<rt>きん</rt></ruby><ruby>曜<rt>よう</rt></ruby><ruby>日<rt>び</rt></ruby>";
[webView loadHTMLString:htmlString baseURL:nil];
[frontView addSubview:webView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(flip)];
[self.view addGestureRecognizer:tap];
}
Issue: I notice that on the first time I press the button to transition to the second view controller that there is a delay in seeing the html string loaded to the webview (it's only about 0.5 - 1 second). This doesn't happen if I go back to the first view controller and hit the button again - this time it's instant.
Any ideas what might be causing this first time delay and how to avoid it?
Thanks