Skip to content

Commit

Permalink
Some bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
graetzer committed Jul 14, 2012
1 parent 4f83950 commit 272803e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Demo/SGTabs/SGAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ - (void)openTab {
}

- (BOOL)canRemoveTab:(UIViewController *)viewController {
return self.tabController.count > 1;
return YES;//self.tabController.count > 1;
}
@end
27 changes: 26 additions & 1 deletion Demo/SGTabs/SGViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ - (void)viewDidLoad
[super viewDidLoad];

self.webView.delegate = self;
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 300.0, 25.0)];
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400.0, 25.0)];
self.textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.textField.backgroundColor = [UIColor whiteColor];
self.textField.text = @"http://www.google.com";
self.textField.clearButtonMode = UITextFieldViewModeAlways;
Expand Down Expand Up @@ -67,6 +68,30 @@ - (void)viewDidUnload
[super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated {
#ifdef DEBUG
NSLog(@"%s", __FUNCTION__);
#endif
}

- (void)viewDidAppear:(BOOL)animated {
#ifdef DEBUG
NSLog(@"%s", __FUNCTION__);
#endif
}

- (void)viewWillDisappear:(BOOL)animated {
#ifdef DEBUG
NSLog(@"%s", __FUNCTION__);
#endif
}

- (void)viewDidDisappear:(BOOL)animated {
#ifdef DEBUG
NSLog(@"%s", __FUNCTION__);
#endif
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
Expand Down
8 changes: 4 additions & 4 deletions Source/SGTabView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)title
_cap = kCornerRadius/frame.size.width;
self.contentStretch = CGRectMake(_cap, 0.0, 1.0, 1-_cap);


self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.titleLabel.textAlignment = UITextAlignmentCenter;
self.titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
Expand Down Expand Up @@ -78,9 +78,9 @@ - (void)layoutSubviews {
if (t.width > b.size.width*0.75) {
t.width = b.size.width*0.75 - 2*margin;
}

if(!self.closeButton.hidden) {
self.titleLabel.frame = CGRectMake((b.size.width - t.width)/2 - margin,
self.titleLabel.frame = CGRectMake((b.size.width - t.width)/2 + margin,
(b.size.height - t.height)/2,
t.width, t.height);
} else {
Expand All @@ -89,7 +89,7 @@ - (void)layoutSubviews {
t.width, t.height);
}

self.closeButton.frame = CGRectMake(b.size.width - 2*margin - 25, 0, 25, b.size.height);
self.closeButton.frame = CGRectMake(2*margin, 0, 25, b.size.height);
}

- (void)setTitle:(NSString *)title {
Expand Down
92 changes: 39 additions & 53 deletions Source/SGTabsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,30 @@ - (void)addTab:(UIViewController *)viewController {
options:NSKeyValueObservingOptionNew
context:NULL];

if (!self.currentViewController) {
[self.tabsView addTab:viewController.title];
[self.view addSubview:viewController.view];
_currentViewController = viewController;
[viewController didMoveToParentViewController:self];
if (_toobarVisible)
[self.toolbar setItems:self.currentViewController.toolbarItems animated:YES];

return;
}

[self.currentViewController viewWillDisappear:YES];
// Add tab selects automatically the new tab
[UIView transitionWithView:self.view
duration:kAddTabDuration
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.tabsView addTab:viewController.title];
if (self.currentViewController) {
[self.currentViewController.view removeFromSuperview];
}
[self.view addSubview:viewController.view];
}
completion:^(BOOL finished){
[self.currentViewController viewDidDisappear:YES];
_currentViewController = viewController;

if (_toobarVisible)
[self.toolbar setItems:self.currentViewController.toolbarItems animated:YES];
[viewController didMoveToParentViewController:self];
}];
if (_toobarVisible)
[self.toolbar setItems:viewController.toolbarItems animated:YES];
[self transitionFromViewController:self.currentViewController
toViewController:viewController
duration:kAddTabDuration
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.tabsView addTab:viewController.title];
}
completion:^(BOOL finished){
_currentViewController = viewController;
[viewController didMoveToParentViewController:self];
}];
}
}

Expand Down Expand Up @@ -201,19 +204,10 @@ - (void)removeViewController:(UIViewController *)viewController index:(NSUIntege
if (self.tabContents.count == 0) {//View controller was the last one
[viewController willMoveToParentViewController:nil];
_currentViewController = nil;
[viewController viewWillDisappear:NO];
[UIView transitionWithView:self.tabsView
duration:kRemoveTabDuration
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[viewController.view removeFromSuperview];
[self.tabsView removeTab:index];
[self.toolbar setItems:nil animated:NO];
}
completion:^(BOOL finished){
[viewController viewDidDisappear:NO];
[viewController removeFromParentViewController];
}];
[viewController.view removeFromSuperview];
[self.tabsView removeTab:index];
[self.toolbar setItems:nil animated:YES];
[viewController removeFromParentViewController];
return;
} else if (oldIndex >= self.tabContents.count) {
index = self.tabContents.count-1;
Expand All @@ -224,26 +218,18 @@ - (void)removeViewController:(UIViewController *)viewController index:(NSUIntege
if (_toobarVisible)
[self.toolbar setItems:to.toolbarItems animated:YES];

[viewController willMoveToParentViewController:nil];
[viewController viewWillDisappear:YES];
[UIView transitionWithView:self.view
duration:kRemoveTabDuration
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.tabsView removeTab:oldIndex];

if (self.currentViewController == viewController) {
[viewController.view removeFromSuperview];
self.tabsView.selected = index;
[self.view addSubview:to.view];
}
}
completion:^(BOOL finished){
[viewController viewDidDisappear:YES];
[viewController removeFromParentViewController];
_currentViewController = to;
}];

[self transitionFromViewController:viewController
toViewController:to
duration:kRemoveTabDuration
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.tabsView removeTab:oldIndex];
self.tabsView.selected = index;
}
completion:^(BOOL finished){
[viewController removeFromParentViewController];
_currentViewController = to;
}];
}

- (void)removeViewController:(UIViewController *)viewController {
Expand Down

0 comments on commit 272803e

Please sign in to comment.