I found the difference between iOS 4 and iOS 5 that caused an error in my code. When I create UIWebView, he also created a subview called UIWebBrowserViewwith a frame size of 577 x 533. Then I load the PDF file into UIWebView, and here it is different from iOS 4 and 5. In iOS 4, when the processing reaches the method "webViewDidFinishLoad:", UIWebBrowserViewit still exists with a frame of 577 x 2947 (pdf size, I suppose), but in iOS 5 it UIWebBrowserViewno longer exists and place it there UIWebPDFViewwith a frame of 577 x 533 (here I expected a frame of 577 x 2947). Finally, I trigger the event and views as I expected ( UIWebBrowserViewwith a 577 x 2947 frame in iOS 4 and UIWebPDFViewwith a 577 x 2947.4 frame in iOS 5).
The problem is that when loading the pdf file, when the processing reaches the "webViewDidFinishLoad:" method, I would like to put notes in the PDF file, but this method UIWebPDFViewdoes not yet have a real PDF size. If I just put notes, they will not appear. On iOS 4, it worked, but on iOS 5, it no longer works. Can anyone help on how I can put notes in a web view upload?
Here is the code that shows the different behavior of iOS and below the log.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIWebViewDelegate, UIGestureRecognizerDelegate>
{
IBOutlet UIView *view;
IBOutlet UIWebView * webView;
}
- (void)handleTap:(UITapGestureRecognizer *)recognizer;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[webView setUserInteractionEnabled:YES];
[view bringSubviewToFront:webView];
NSString *path = [[NSBundle mainBundle] pathForResource:@"pdf_teste" ofType:@"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:path];
[webView loadData:pdfData MIMEType:@"text/pdf" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
NSLog(@"On viewDidLoad: %@", [[webView viewForZoomingInScrollView:(UIScrollView *)[[webView subviews] objectAtIndex:0]] description]);
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
recognizer.delegate = self;
[webView addGestureRecognizer:recognizer];
}
- (void)webViewDidFinishLoad:(UIWebView *)view
{
NSLog(@"On webViewDidFinishLoad: %@", [[webView viewForZoomingInScrollView:(UIScrollView *)[[webView subviews] objectAtIndex:0]] description]);
}
- (void)handleTap:(UITapGestureRecognizer *)recognizer
{
NSLog(@"On Tap Event: %@", [[webView viewForZoomingInScrollView:(UIScrollView *)[[webView subviews] objectAtIndex:0]] description]);
}
@end
Log:
iOS 5.1
2012-03-30 14: 24: 28.075 WebViewTest [173: 707] On viewDidLoad:>
2012-03-30 14: 24: 28.823 WebViewTest [173: 707] In webViewDidFinishLoad:> Mar 30 14:24:29 iPad2-de-ASDS WebViewTest [173]: OPDILG + TT857o00: FT_Select_Charmap error: error 38.
2012-03-30 14: 24: 47.167 WebViewTest [173: 707] In Pan Event:>
iOS 4.3.5
2012-03-30 14: 13: 46.285 WebViewTest [823: 607] On viewDidLoad: >
2012-03-30 14: 13: 47.049 WebViewTest [823: 607] webViewDidFinishLoad: > 30 14:13:47 BNBConsult01 WebViewTest [823]: OPDILG + TT857o00: FT_Select_Charmap: 38.
2012-03-30 14: 14: 48.199 WebViewTest [823: 607] Pan Event: >