diff --git a/MoreDemos/EmbeddedYoutubePatch/EmbeddedYoutubePatch.xcodeproj/project.pbxproj b/MoreDemos/EmbeddedYoutubePatch/EmbeddedYoutubePatch.xcodeproj/project.pbxproj index e905f30..fc41ad4 100644 --- a/MoreDemos/EmbeddedYoutubePatch/EmbeddedYoutubePatch.xcodeproj/project.pbxproj +++ b/MoreDemos/EmbeddedYoutubePatch/EmbeddedYoutubePatch.xcodeproj/project.pbxproj @@ -287,6 +287,7 @@ 6FBF4B7D14F7EACF0048C98E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "EmbeddedYoutubePatch/EmbeddedYoutubePatch-Prefix.pch"; INFOPLIST_FILE = "EmbeddedYoutubePatch/EmbeddedYoutubePatch-Info.plist"; @@ -298,6 +299,7 @@ 6FBF4B7E14F7EACF0048C98E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "EmbeddedYoutubePatch/EmbeddedYoutubePatch-Prefix.pch"; INFOPLIST_FILE = "EmbeddedYoutubePatch/EmbeddedYoutubePatch-Info.plist"; @@ -325,6 +327,7 @@ 6FBF4B7E14F7EACF0048C98E /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/TSMiniWebBrowser/TSMiniWebBrowser.h b/TSMiniWebBrowser/TSMiniWebBrowser.h index 82d5a52..a43a402 100644 --- a/TSMiniWebBrowser/TSMiniWebBrowser.h +++ b/TSMiniWebBrowser/TSMiniWebBrowser.h @@ -73,11 +73,12 @@ typedef enum { @property (nonatomic, assign) BOOL showPageTitleOnTitleBar; @property (nonatomic, assign) BOOL showReloadButton; @property (nonatomic, assign) BOOL showActionButton; +@property (nonatomic, assign) BOOL showNavigationBarInModalMode; // Only used in modal mode @property (nonatomic, assign) UIBarStyle barStyle; -@property (nonatomic, strong) UIColor *barTintColor; -@property (nonatomic, strong) NSString *modalDismissButtonTitle; -@property (nonatomic, strong) NSString *domainLockList; -@property (nonatomic, strong) NSString *currentURL; +@property (nonatomic, retain) UIColor *barTintColor; +@property (nonatomic, retain) NSString *modalDismissButtonTitle; +@property (nonatomic, retain) NSString *domainLockList; +@property (nonatomic, retain) NSString *currentURL; // Public Methods - (id)initWithUrl:(NSURL*)url; diff --git a/TSMiniWebBrowser/TSMiniWebBrowser.m b/TSMiniWebBrowser/TSMiniWebBrowser.m index 0c8a9f5..8904531 100644 --- a/TSMiniWebBrowser/TSMiniWebBrowser.m +++ b/TSMiniWebBrowser/TSMiniWebBrowser.m @@ -39,6 +39,7 @@ @implementation TSMiniWebBrowser @synthesize barTintColor; @synthesize domainLockList; @synthesize currentURL; +@synthesize showNavigationBarInModalMode; #define kToolBarHeight 44 #define kTabBarHeight 49 @@ -88,21 +89,26 @@ -(void) dismissController { } } +-(UIBarButtonItem *)doneButton{ + return [[[UIBarButtonItem alloc] initWithTitle:modalDismissButtonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(dismissController)] autorelease]; +} + //Added in the dealloc method to remove the webview delegate, because if you use this in a navigation controller //TSMiniWebBrowser can get deallocated while the page is still loading and the web view will call its delegate-- resulting in a crash -(void)dealloc { [webView setDelegate:nil]; + [modalDismissButtonTitle release]; + [domainLockList release]; + [currentURL release]; + [super dealloc]; } #pragma mark - Init - // This method is only used in modal mode -(void) initTitleBar { - UIBarButtonItem *buttonDone = [[UIBarButtonItem alloc] initWithTitle:modalDismissButtonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(dismissController)]; - - UINavigationItem *titleBar = [[UINavigationItem alloc] initWithTitle:@""]; - titleBar.leftBarButtonItem = buttonDone; + UINavigationItem *titleBar = [[[UINavigationItem alloc] initWithTitle:@""] autorelease]; + titleBar.leftBarButtonItem = [self doneButton]; CGFloat width = self.view.frame.size.width; navigationBarModal = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, width, 44)]; @@ -132,29 +138,29 @@ -(void) initToolBar { buttonGoBack = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTouchUp:)]; - UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; + UIBarButtonItem *fixedSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease]; fixedSpace.width = 30; buttonGoForward = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(forwardButtonTouchUp:)]; - UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; + UIBarButtonItem *flexibleSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]; - UIBarButtonItem *buttonReload = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reload_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(reloadButtonTouchUp:)]; + UIBarButtonItem *buttonReload = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reload_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(reloadButtonTouchUp:)] autorelease]; - UIBarButtonItem *fixedSpace2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; + UIBarButtonItem *fixedSpace2 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease]; fixedSpace2.width = 20; - UIBarButtonItem *buttonAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(buttonActionTouchUp:)]; + UIBarButtonItem *buttonAction = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(buttonActionTouchUp:)] autorelease]; // Activity indicator is a bit special activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; activityIndicator.frame = CGRectMake(11, 7, 20, 20); - UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 43, 33)]; + UIView *containerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 43, 33)] autorelease]; [containerView addSubview:activityIndicator]; - UIBarButtonItem *buttonContainer = [[UIBarButtonItem alloc] initWithCustomView:containerView]; + UIBarButtonItem *buttonContainer = [[[UIBarButtonItem alloc] initWithCustomView:containerView] autorelease]; // Add butons to an array - NSMutableArray *toolBarButtons = [[NSMutableArray alloc] init]; + NSMutableArray *toolBarButtons = [[[NSMutableArray alloc] init] autorelease]; [toolBarButtons addObject:buttonGoBack]; [toolBarButtons addObject:fixedSpace]; [toolBarButtons addObject:buttonGoForward]; @@ -167,6 +173,9 @@ -(void) initToolBar { [toolBarButtons addObject:fixedSpace2]; [toolBarButtons addObject:buttonAction]; } + if(showNavigationBarInModalMode == NO){ + [toolBarButtons addObject:[self doneButton]]; + } // Set buttons to tool bar [toolBar setItems:toolBarButtons animated:YES]; @@ -178,7 +187,9 @@ -(void) initToolBar { -(void) initWebView { CGSize viewSize = self.view.frame.size; if (mode == TSMiniWebBrowserModeModal) { - webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, kToolBarHeight, viewSize.width, viewSize.height-kToolBarHeight*2)]; + int webY = showNavigationBarInModalMode ? kToolBarHeight : 0; + int webHeight = showNavigationBarInModalMode ? kToolBarHeight*2 : kToolBarHeight*1; + webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, webY, viewSize.width, viewSize.height-webHeight)]; } else if(mode == TSMiniWebBrowserModeNavigation) { webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height-kToolBarHeight)]; } else if(mode == TSMiniWebBrowserModeTabBar) { @@ -208,6 +219,7 @@ - (id)initWithUrl:(NSURL*)url { // Defaults mode = TSMiniWebBrowserModeNavigation; showURLStringOnActionSheetTitle = YES; + showNavigationBarInModalMode = YES; showPageTitleOnTitleBar = YES; showReloadButton = YES; showActionButton = YES; @@ -247,8 +259,8 @@ - (void)viewDidLoad // Init web view [self initWebView]; - // Init title bar if presented modally - if (mode == TSMiniWebBrowserModeModal) { + // Init title bar if presented modally and needed + if (mode == TSMiniWebBrowserModeModal && showNavigationBarInModalMode) { [self initTitleBar]; } @@ -301,7 +313,7 @@ -(void) viewWillDisappear:(BOOL)animated { - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations - return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); + return YES; } /* Fix for landscape + zooming webview bug. @@ -350,7 +362,7 @@ - (void)showActionSheet { NSURL* url = [webView.request URL]; urlString = [url absoluteString]; } - UIActionSheet *actionSheet = [[UIActionSheet alloc] init]; + UIActionSheet *actionSheet = [[[UIActionSheet alloc] init] autorelease]; actionSheet.title = urlString; actionSheet.delegate = self; [actionSheet addButtonWithTitle:NSLocalizedString(@"Open in Safari", nil)]; @@ -470,7 +482,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) { if (navigationType == UIWebViewNavigationTypeLinkClicked) { - currentURL = request.URL.absoluteString; + self.currentURL = request.URL.absoluteString; } return YES; @@ -500,7 +512,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) { if (navigationType == UIWebViewNavigationTypeLinkClicked) { - currentURL = request.URL.absoluteString; + self.currentURL = request.URL.absoluteString; } return YES; @@ -544,6 +556,7 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", nil), nil]; [alert show]; + [alert release]; } @end diff --git a/TSMiniWebBrowserDemo.xcodeproj/project.pbxproj b/TSMiniWebBrowserDemo.xcodeproj/project.pbxproj index e5707d8..251d9fd 100644 --- a/TSMiniWebBrowserDemo.xcodeproj/project.pbxproj +++ b/TSMiniWebBrowserDemo.xcodeproj/project.pbxproj @@ -318,6 +318,7 @@ 6F69CDCF14C6339C00BB6C57 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TSMiniWebBrowserDemo/TSMiniWebBrowserDemo-Prefix.pch"; INFOPLIST_FILE = "TSMiniWebBrowserDemo/TSMiniWebBrowserDemo-Info.plist"; @@ -330,6 +331,7 @@ 6F69CDD014C6339C00BB6C57 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TSMiniWebBrowserDemo/TSMiniWebBrowserDemo-Prefix.pch"; INFOPLIST_FILE = "TSMiniWebBrowserDemo/TSMiniWebBrowserDemo-Info.plist"; diff --git a/TSMiniWebBrowserDemo/ViewController.h b/TSMiniWebBrowserDemo/ViewController.h index 647364e..4c2a25f 100644 --- a/TSMiniWebBrowserDemo/ViewController.h +++ b/TSMiniWebBrowserDemo/ViewController.h @@ -30,6 +30,7 @@ @interface ViewController : UIViewController { } -- (IBAction)buttonTouchUp:(id)sender; +- (IBAction)navigationTouchUp:(id)sender; +- (IBAction)modalTouchUp:(id)sender; @end diff --git a/TSMiniWebBrowserDemo/ViewController.m b/TSMiniWebBrowserDemo/ViewController.m index 81b4f2f..ca50c02 100644 --- a/TSMiniWebBrowserDemo/ViewController.m +++ b/TSMiniWebBrowserDemo/ViewController.m @@ -28,71 +28,34 @@ @implementation ViewController -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; - // Release any cached data, images, etc that aren't in use. -} - -#pragma mark - View lifecycle - -- (void)viewDidLoad -{ - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. -} - -- (void)viewDidUnload -{ - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; -} - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; -} - -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; -} - -- (void)viewWillDisappear:(BOOL)animated -{ - [super viewWillDisappear:animated]; -} - -- (void)viewDidDisappear:(BOOL)animated -{ - [super viewDidDisappear:animated]; -} -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - // Return YES for supported orientations - return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); -} - -- (IBAction)buttonTouchUp:(id)sender { +- (IBAction)navigationTouchUp:(id)sender { TSMiniWebBrowser *webBrowser = [[TSMiniWebBrowser alloc] initWithUrl:[NSURL URLWithString:@"http://indiedevstories.com"]]; webBrowser.delegate = self; -// webBrowser.showURLStringOnActionSheetTitle = YES; -// webBrowser.showPageTitleOnTitleBar = YES; -// webBrowser.showActionButton = YES; -// webBrowser.showReloadButton = YES; -// [webBrowser setFixedTitleBarText:@"Test Title Text"]; // This has priority over "showPageTitleOnTitleBar". + // webBrowser.showURLStringOnActionSheetTitle = YES; + // webBrowser.showPageTitleOnTitleBar = YES; + // webBrowser.showActionButton = YES; + // webBrowser.showReloadButton = YES; + // [webBrowser setFixedTitleBarText:@"Test Title Text"]; // This has priority over "showPageTitleOnTitleBar". webBrowser.mode = TSMiniWebBrowserModeNavigation; webBrowser.barStyle = UIBarStyleBlack; - if (webBrowser.mode == TSMiniWebBrowserModeModal) { - webBrowser.modalDismissButtonTitle = @"Home"; - [self presentModalViewController:webBrowser animated:YES]; - } else if(webBrowser.mode == TSMiniWebBrowserModeNavigation) { - [self.navigationController pushViewController:webBrowser animated:YES]; - } + [self.navigationController pushViewController:webBrowser animated:YES]; + [webBrowser release]; +} + +- (IBAction)modalTouchUp:(id)sender { + TSMiniWebBrowser *webBrowser = [[TSMiniWebBrowser alloc] initWithUrl:[NSURL URLWithString:@"http://indiedevstories.com"]]; + webBrowser.delegate = self; + webBrowser.mode = TSMiniWebBrowserModeModal; + webBrowser.barStyle = UIBarStyleBlack; + webBrowser.showActionButton = YES; + //webBrowser.showNavigationBarInModalMode = NO; + + webBrowser.modalDismissButtonTitle = @"Close"; + [self presentModalViewController:webBrowser animated:YES]; + [webBrowser release]; } #pragma mark - TSMiniWebBrowserDelegate diff --git a/TSMiniWebBrowserDemo/en.lproj/ViewController.xib b/TSMiniWebBrowserDemo/en.lproj/ViewController.xib index cefd754..90a4711 100644 --- a/TSMiniWebBrowserDemo/en.lproj/ViewController.xib +++ b/TSMiniWebBrowserDemo/en.lproj/ViewController.xib @@ -1,19 +1,19 @@ - 1280 - 11C74 - 1938 - 1138.23 - 567.00 + 1536 + 12C2034 + 2844 + 1187.34 + 625.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 933 + 1930 IBProxyObject - IBUIView IBUIButton + IBUIView com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -38,17 +38,18 @@ 292 - {{77, 211}, {166, 37}} + {{77, 121}, {166, 44}} - + + _NS:225 NO IBCocoaTouchFramework 0 0 1 - TSMiniWebBrowser - + Mode Navigation + 3 MQA @@ -56,23 +57,47 @@ 1 MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - + 3 MC41AA - + 2 15 - + Helvetica-Bold 15 16 + + + 292 + {{77, 208}, {166, 44}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Mode Modal + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + + {{0, 20}, {320, 460}} + 3 @@ -98,12 +123,21 @@ - buttonTouchUp: + navigationTouchUp: 7 - 9 + 12 + + + + modalTouchUp: + + + 7 + + 13 @@ -130,6 +164,7 @@ + @@ -138,6 +173,11 @@ + + 10 + + + @@ -145,6 +185,7 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -152,13 +193,38 @@ - 9 + 13 + + + + + ViewController + UIViewController + + id + id + + + + modalTouchUp: + id + + + navigationTouchUp: + id + + + + IBProjectSource + ./Classes/ViewController.h + + + - 0 IBCocoaTouchFramework YES 3 - 933 + 1930