Skip to content

Commit

Permalink
Consistent toolbar animations
Browse files Browse the repository at this point in the history
Consistent toolbar animations
Removed redundant file references in the project file
Added a how to use
  • Loading branch information
graetzer committed Jun 19, 2012
1 parent c166f8b commit e37786e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 43 deletions.
25 changes: 0 additions & 25 deletions Demo/SGTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@
F470D2AE1580ECE700ED3644 /* SGTabView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabView.m; sourceTree = "<group>"; };
F470D2B01580ED3000ED3644 /* SGToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGToolbar.h; sourceTree = "<group>"; };
F470D2B11580ED3000ED3644 /* SGToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGToolbar.m; sourceTree = "<group>"; };
F476BFBF15816C8E00BABEEB /* SGTabView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabView.h; sourceTree = "<group>"; };
F476BFC015816C8E00BABEEB /* SGTabView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabView.m; sourceTree = "<group>"; };
F476BFC115816C8E00BABEEB /* SGToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGToolbar.h; sourceTree = "<group>"; };
F476BFC215816C8E00BABEEB /* SGToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGToolbar.m; sourceTree = "<group>"; };
F476BFC315816C8E00BABEEB /* SGTabsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabsView.h; sourceTree = "<group>"; };
F476BFC415816C8E00BABEEB /* SGTabsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabsView.m; sourceTree = "<group>"; };
F476BFC515816C8E00BABEEB /* SGTabsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabsViewController.h; sourceTree = "<group>"; };
F476BFC615816C8E00BABEEB /* SGTabsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabsViewController.m; sourceTree = "<group>"; };
F493636B158686E200FBD5F3 /* SGTabDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SGTabDefines.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -108,7 +100,6 @@
F470D2901580EA5100ED3644 /* SGViewController.h */,
F470D2911580EA5100ED3644 /* SGViewController.m */,
F470D2931580EA5100ED3644 /* SGViewController.xib */,
F476BFBE15816C8E00BABEEB /* Source */,
F470D2851580EA5100ED3644 /* Supporting Files */,
);
name = Demo;
Expand Down Expand Up @@ -144,22 +135,6 @@
path = ../Source;
sourceTree = "<group>";
};
F476BFBE15816C8E00BABEEB /* Source */ = {
isa = PBXGroup;
children = (
F476BFBF15816C8E00BABEEB /* SGTabView.h */,
F476BFC015816C8E00BABEEB /* SGTabView.m */,
F476BFC115816C8E00BABEEB /* SGToolbar.h */,
F476BFC215816C8E00BABEEB /* SGToolbar.m */,
F476BFC315816C8E00BABEEB /* SGTabsView.h */,
F476BFC415816C8E00BABEEB /* SGTabsView.m */,
F476BFC515816C8E00BABEEB /* SGTabsViewController.h */,
F476BFC615816C8E00BABEEB /* SGTabsViewController.m */,
);
name = Source;
path = ../../Source;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down
2 changes: 2 additions & 0 deletions Demo/SGTabs/SGViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ - (void)viewDidLoad
self.textField.backgroundColor = [UIColor whiteColor];
self.textField.text = @"http://www.google.com";
self.textField.clearButtonMode = UITextFieldViewModeAlways;
self.textField.keyboardType = UIKeyboardTypeURL;
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.delegate = self;
[self textFieldDidEndEditing:self.textField];

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Tab component for iOS 5+. You can show your ViewControllers in tabs, it is possi
- User can remove tabs by pressing an X on a tab. TODO
- Dynamically show and hide a UIToolbar at the top
- Show the UIBarButtonItems in viewController.toolbarItems in the toolbar
- Enables you to build mobile Safari style Apps
- Enables you to build mobile Safari style Apps. (See demo

# Demo
A basic web browser with tabs, in around 120 lines of code.
Expand All @@ -17,6 +17,11 @@ A basic web browser with tabs, in around 120 lines of code.

![Multiple tabs](https://github.com/graetzer/SGTabs/raw/master/screen.png "A basic browser with visible toolbar")

# How to use
- Just include all files in the "./Source" Directory. Everything else is just for demonstrational purposes
- This is an ARC Project, so remember to enable ARC at least on the SGTabs files.
- Add the "-fobjc-arc" flag (In your project's target settings -> BuildPhases -> Compile Sources)
- Use as in the Demo or subclass SGTabsViewController and use it as an root view controller


# Licence
Expand Down
2 changes: 1 addition & 1 deletion Source/SGTabsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@interface SGTabsView : UIView <UIGestureRecognizerDelegate>
@property (nonatomic, weak) SGTabsViewController *tabsController;
@property (nonatomic, readonly) NSMutableArray *tabs;
@property (nonatomic, readonly, strong) NSMutableArray *tabs;
@property (nonatomic, assign) NSUInteger selected;

- (void)addTab:(NSString *)title;
Expand Down
3 changes: 1 addition & 2 deletions Source/SGTabsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
BOOL _editable;
CGRect _contentFrame;
BOOL _toobarVisible;
__weak UIViewController *_currentViewController;
}

/// Is an optional delegate
Expand All @@ -47,7 +46,7 @@
/// Currently visible view controller
@property (nonatomic, readonly, weak) UIViewController *currentViewController;

@property (nonatomic, readonly) NSMutableArray *tabContents;
@property (nonatomic, readonly, strong) NSMutableArray *tabContents;

- (id)initEditable:(BOOL)editable;

Expand Down
28 changes: 14 additions & 14 deletions Source/SGTabsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ - (void)addTab:(UIViewController *)viewController {
options:NSKeyValueObservingOptionNew
context:NULL];

if (_toobarVisible)
[self.toolbar setItems:viewController.toolbarItems animated:YES];

// Add tab selects automatically the new tab
[UIView transitionWithView:self.view
Expand All @@ -141,12 +139,13 @@ - (void)addTab:(UIViewController *)viewController {
[self.currentViewController.view removeFromSuperview];
[self.currentViewController viewDidDisappear:YES];
}

_currentViewController = viewController;
[self.view addSubview:viewController.view];
}
completion:^(BOOL finished){
if (_toobarVisible)
[self.toolbar setItems:self.currentViewController.toolbarItems animated:YES];
[viewController didMoveToParentViewController:self];
_currentViewController = viewController;
}];
}
}
Expand Down Expand Up @@ -226,11 +225,13 @@ - (void)removeViewController:(UIViewController *)viewController index:(NSUIntege
}

UIViewController *to = [self.tabContents objectAtIndex:index];
if (_toobarVisible)
[self.toolbar setItems:to.toolbarItems animated:YES];

[viewController willMoveToParentViewController:nil];
[UIView transitionWithView:self.view
duration:kRemoveTabDuration
options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionCurveEaseInOut
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.tabsView removeTab:index];

Expand All @@ -242,8 +243,7 @@ - (void)removeViewController:(UIViewController *)viewController index:(NSUIntege
self.tabsView.selected = index;
to.view.frame = _contentFrame;
[self.view addSubview:to.view];
if (_toobarVisible)
[self.toolbar setItems:to.toolbarItems animated:NO];

}
}
completion:^(BOOL finished){
Expand Down Expand Up @@ -277,19 +277,19 @@ - (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated {
tabs.origin.y = toolbarHeight;
_contentFrame.origin.y = head.size.height;

_toobarVisible = !hidden;
if (_toobarVisible)
[self.toolbar setItems:self.currentViewController.toolbarItems animated:animated];
else
[self.toolbar setItems:nil animated:animated];

[UIView animateWithDuration:animated ? 0.3 : 0
animations:^{
self.currentViewController.view.frame = _contentFrame;
self.headerView.frame = head;
self.toolbar.frame = toolbar;
self.tabsView.frame = tabs;
}];
} completion: ^(BOOL finished){
_toobarVisible = !hidden;
if (_toobarVisible)
[self.toolbar setItems:self.currentViewController.toolbarItems animated:animated];
else
[self.toolbar setItems:nil animated:animated];
}];
}

- (BOOL)toolbarHidden {
Expand Down

0 comments on commit e37786e

Please sign in to comment.