From bea89966cb9026682cef0650f762f46a1553aa4c Mon Sep 17 00:00:00 2001 From: Christian Beck Date: Fri, 5 Dec 2014 13:37:19 +0100 Subject: [PATCH 1/3] removed accented character in parameter name --- SVWebViewController/SVWebViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index 2714aaf..f651abd 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -283,7 +283,7 @@ - (void)actionButtonTapped:(id)sender { } } -- (void)doneButtonTapped:(id)sùender { +- (void)doneButtonTapped:(id)sender { [self dismissViewControllerAnimated:YES completion:NULL]; } From fd6cddec3a8c2d521dc7ab16b72708ecd898c77b Mon Sep 17 00:00:00 2001 From: Christian Beck Date: Fri, 5 Dec 2014 13:40:53 +0100 Subject: [PATCH 2/3] checking for file URLs with build-in method --- SVWebViewController/SVWebViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index f651abd..10ca7d7 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -262,7 +262,7 @@ - (void)actionButtonTapped:(id)sender { if (url != nil) { NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]]; - if ([[url absoluteString] hasPrefix:@"file:///"]) { + if (url.fileURL) { UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url]; [dc presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES]; } else { From ee8786263200ed0863cae24219a44c973186aa16 Mon Sep 17 00:00:00 2001 From: Christian Beck Date: Fri, 25 Sep 2015 13:49:25 +0200 Subject: [PATCH 3/3] added scalesPageToFit parameter for all init methods --- .../SVModalWebViewController.h | 3 ++ .../SVModalWebViewController.m | 18 +++++-- SVWebViewController/SVWebViewController.h | 3 ++ SVWebViewController/SVWebViewController.m | 52 ++++++++++++------- 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/SVWebViewController/SVModalWebViewController.h b/SVWebViewController/SVModalWebViewController.h index c8ff5ca..8363c53 100644 --- a/SVWebViewController/SVModalWebViewController.h +++ b/SVWebViewController/SVModalWebViewController.h @@ -11,8 +11,11 @@ @interface SVModalWebViewController : UINavigationController - (instancetype)initWithAddress:(NSString*)urlString; +- (instancetype)initWithAddress:(NSString*)urlString scalesPageToFit:(BOOL)scalesPageToFit; - (instancetype)initWithURL:(NSURL *)URL; +- (instancetype)initWithURL:(NSURL *)URL scalesPageToFit:(BOOL)scalesPageToFit; - (instancetype)initWithURLRequest:(NSURLRequest *)request; +- (instancetype)initWithURLRequest:(NSURLRequest *)request scalesPageToFit:(BOOL)scalesPageToFit; @property (nonatomic, strong) UIColor *barsTintColor; diff --git a/SVWebViewController/SVModalWebViewController.m b/SVWebViewController/SVModalWebViewController.m index 38cfd13..166d6d9 100644 --- a/SVWebViewController/SVModalWebViewController.m +++ b/SVWebViewController/SVModalWebViewController.m @@ -31,17 +31,29 @@ - (instancetype)initWithAddress:(NSString*)urlString { return [self initWithURL:[NSURL URLWithString:urlString]]; } +- (instancetype)initWithAddress:(NSString*)urlString scalesPageToFit:(BOOL)scalesPageToFit { + return [self initWithURL:[NSURL URLWithString:urlString] scalesPageToFit:scalesPageToFit]; +} + - (instancetype)initWithURL:(NSURL *)URL { return [self initWithURLRequest:[NSURLRequest requestWithURL:URL]]; } +- (instancetype)initWithURL:(NSURL *)URL scalesPageToFit:(BOOL)scalesPageToFit { + return [self initWithURLRequest:[NSURLRequest requestWithURL:URL] scalesPageToFit:scalesPageToFit]; +} + - (instancetype)initWithURLRequest:(NSURLRequest *)request { - self.webViewController = [[SVWebViewController alloc] initWithURLRequest:request]; + return [self initWithURLRequest:request scalesPageToFit:YES]; +} + +- (instancetype)initWithURLRequest:(NSURLRequest *)request scalesPageToFit:(BOOL)scalesPageToFit { + self.webViewController = [[SVWebViewController alloc] initWithURLRequest:request scalesPageToFit:scalesPageToFit]; if (self = [super initWithRootViewController:self.webViewController]) { UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self.webViewController action:@selector(doneButtonTapped:)]; - + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) self.webViewController.navigationItem.leftBarButtonItem = doneButton; else @@ -52,7 +64,7 @@ - (instancetype)initWithURLRequest:(NSURLRequest *)request { - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:NO]; - + self.webViewController.title = self.title; self.navigationBar.tintColor = self.barsTintColor; } diff --git a/SVWebViewController/SVWebViewController.h b/SVWebViewController/SVWebViewController.h index ccd90bf..c619483 100644 --- a/SVWebViewController/SVWebViewController.h +++ b/SVWebViewController/SVWebViewController.h @@ -9,7 +9,10 @@ @interface SVWebViewController : UIViewController - (instancetype)initWithAddress:(NSString*)urlString; +- (instancetype)initWithAddress:(NSString*)urlString scalesPageToFit:(BOOL)scalesPageToFit; - (instancetype)initWithURL:(NSURL*)URL; +- (instancetype)initWithURL:(NSURL*)URL scalesPageToFit:(BOOL)scalesPageToFit; - (instancetype)initWithURLRequest:(NSURLRequest *)request; +- (instancetype)initWithURLRequest:(NSURLRequest*)request scalesPageToFit:(BOOL)scalesPageToFit; @end diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index 10ca7d7..4a4bc0d 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -20,6 +20,7 @@ @interface SVWebViewController () @property (nonatomic, strong) UIWebView *webView; @property (nonatomic, strong) NSURLRequest *request; +@property (nonatomic, assign) BOOL scalesPageToFit; @end @@ -35,17 +36,30 @@ - (void)dealloc { } - (instancetype)initWithAddress:(NSString *)urlString { - return [self initWithURL:[NSURL URLWithString:urlString]]; + return [self initWithURL:[NSURL URLWithString:urlString] scalesPageToFit:YES]; +} + +- (instancetype)initWithAddress:(NSString *)urlString scalesPageToFit:(BOOL)scalesPageToFit { + return [self initWithURL:[NSURL URLWithString:urlString] scalesPageToFit:scalesPageToFit]; } - (instancetype)initWithURL:(NSURL*)pageURL { - return [self initWithURLRequest:[NSURLRequest requestWithURL:pageURL]]; + return [self initWithURLRequest:[NSURLRequest requestWithURL:pageURL] scalesPageToFit:YES]; +} + +- (instancetype)initWithURL:(NSURL*)pageURL scalesPageToFit:(BOOL)scalesPageToFit { + return [self initWithURLRequest:[NSURLRequest requestWithURL:pageURL] scalesPageToFit:scalesPageToFit]; } - (instancetype)initWithURLRequest:(NSURLRequest*)request { + return [self initWithURLRequest:request scalesPageToFit:YES]; +} + +- (instancetype)initWithURLRequest:(NSURLRequest*)request scalesPageToFit:(BOOL)scalesPageToFit { self = [super init]; if (self) { self.request = request; + self.scalesPageToFit = scalesPageToFit; } return self; } @@ -78,9 +92,9 @@ - (void)viewDidUnload { - (void)viewWillAppear:(BOOL)animated { NSAssert(self.navigationController, @"SVWebViewController needs to be contained in a UINavigationController. If you are presenting SVWebViewController modally, use SVModalWebViewController instead."); - + [super viewWillAppear:animated]; - + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { [self.navigationController setToolbarHidden:NO animated:animated]; } @@ -91,7 +105,7 @@ - (void)viewWillAppear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { [self.navigationController setToolbarHidden:YES animated:animated]; } @@ -105,7 +119,7 @@ - (void)viewDidDisappear:(BOOL)animated { - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) return YES; - + return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown; } @@ -115,7 +129,7 @@ - (UIWebView*)webView { if(!_webView) { _webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _webView.delegate = self; - _webView.scalesPageToFit = YES; + _webView.scalesPageToFit = self.scalesPageToFit; } return _webView; } @@ -168,16 +182,16 @@ - (UIBarButtonItem *)actionBarButtonItem { - (void)updateToolbarItems { self.backBarButtonItem.enabled = self.self.webView.canGoBack; self.forwardBarButtonItem.enabled = self.self.webView.canGoForward; - + UIBarButtonItem *refreshStopBarButtonItem = self.self.webView.isLoading ? self.stopBarButtonItem : self.refreshBarButtonItem; - + UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; - + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { CGFloat toolbarWidth = 250.0f; fixedSpace.width = 35.0f; - + NSArray *items = [NSArray arrayWithObjects: fixedSpace, refreshStopBarButtonItem, @@ -188,14 +202,14 @@ - (void)updateToolbarItems { fixedSpace, self.actionBarButtonItem, nil]; - + UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, toolbarWidth, 44.0f)]; toolbar.items = items; toolbar.barStyle = self.navigationController.navigationBar.barStyle; toolbar.tintColor = self.navigationController.navigationBar.tintColor; self.navigationItem.rightBarButtonItems = items.reverseObjectEnumerator.allObjects; } - + else { NSArray *items = [NSArray arrayWithObjects: fixedSpace, @@ -208,7 +222,7 @@ - (void)updateToolbarItems { self.actionBarButtonItem, fixedSpace, nil]; - + self.navigationController.toolbar.barStyle = self.navigationController.navigationBar.barStyle; self.navigationController.toolbar.tintColor = self.navigationController.navigationBar.tintColor; self.toolbarItems = items; @@ -225,11 +239,11 @@ - (void)webViewDidStartLoad:(UIWebView *)webView { - (void)webViewDidFinishLoad:(UIWebView *)webView { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; - + if (self.navigationItem.title == nil) { self.navigationItem.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; } - + [self updateToolbarItems]; } @@ -261,13 +275,13 @@ - (void)actionButtonTapped:(id)sender { NSURL *url = self.webView.request.URL ? self.webView.request.URL : self.request.URL; if (url != nil) { NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]]; - + if (url.fileURL) { UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url]; [dc presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES]; } else { UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:activities]; - + #ifdef __IPHONE_8_0 if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) @@ -277,7 +291,7 @@ - (void)actionButtonTapped:(id)sender { ctrl.barButtonItem = sender; } #endif - + [self presentViewController:activityController animated:YES completion:nil]; } }