Skip to content

Commit

Permalink
Fix an orientation bug in iOS 8, restore tab bar hidden to last state.
Browse files Browse the repository at this point in the history
  • Loading branch information
robbdimitrov committed Nov 8, 2014
1 parent 489a3a5 commit 29f8f75
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 17 deletions.
13 changes: 13 additions & 0 deletions Example/Classes/Controllers/RDVDetailsViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// RDVDetailsViewController.h
// RDVTabBarController
//
// Created by Robert Dimitrov on 11/8/14.
// Copyright (c) 2014 Robert Dimitrov. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RDVDetailsViewController : UIViewController

@end
44 changes: 44 additions & 0 deletions Example/Classes/Controllers/RDVDetailsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// RDVDetailsViewController.m
// RDVTabBarController
//
// Created by Robert Dimitrov on 11/8/14.
// Copyright (c) 2014 Robert Dimitrov. All rights reserved.
//

#import "RDVDetailsViewController.h"
#import "RDVTabBarController.h"

@interface RDVDetailsViewController ()

@end

@implementation RDVDetailsViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"Details";
self.view.backgroundColor = [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1.0];

UILabel *label = [[UILabel alloc] init];
label.text = @"Detail View Controller";
label.frame = CGRectMake(20, 150, CGRectGetWidth(self.view.frame) - 2 * 20, 20);
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
[[self rdv_tabBarController] setTabBarHidden:NO animated:YES];

[super viewWillDisappear:animated];
}

@end
6 changes: 2 additions & 4 deletions Example/Classes/Controllers/RDVFirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa
#pragma mark - Methods

- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath {
[[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %d", self.title, indexPath.row]];
[[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %ld", self.title, (long)indexPath.row]];
}

#pragma mark - Table view
Expand All @@ -96,9 +96,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];

[[self rdv_tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%d", indexPath.row+1]];

[[self rdv_tabBarController] setTabBarHidden:!self.rdv_tabBarController.tabBarHidden animated:YES];
[[self rdv_tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%ld", indexPath.row+1]];
}

@end
4 changes: 3 additions & 1 deletion Example/Classes/Controllers/RDVSecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa
#pragma mark - Methods

- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath {
[[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %d", self.title, indexPath.row]];
[[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %ld", self.title, (long)indexPath.row]];
}

#pragma mark - Table view
Expand All @@ -92,6 +92,8 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];

[[self rdv_tabBarController] setTabBarHidden:!self.rdv_tabBarController.tabBarHidden animated:YES];
}

@end
6 changes: 5 additions & 1 deletion Example/Classes/Controllers/RDVThirdViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#import "RDVThirdViewController.h"
#import "RDVTabBarController.h"
#import "RDVDetailsViewController.h"

@implementation RDVThirdViewController

Expand Down Expand Up @@ -69,7 +70,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa
#pragma mark - Methods

- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath {
[[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %d", self.title, indexPath.row]];
[[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %ld", self.title, (long)indexPath.row]];
}

#pragma mark - Table view
Expand All @@ -92,6 +93,9 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];

UIViewController *viewController = [[RDVDetailsViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
}

@end
4 changes: 2 additions & 2 deletions RDVTabBarController.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "RDVTabBarController"
s.version = "1.1.7"
s.version = "1.1.8"
s.summary = "Highly customizable tabBar and tabBarController for iOS"
s.description = "RDVTabBarController is iPad and iPhone compatible. Supports landscape and portrait orientations and can be used inside UINavigationController."
s.homepage = "https://github.com/robbdimitrov/RDVTabBarController"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "Robert Dimitrov" => "[email protected]" }
s.platform = :ios, '5.0'
s.source = { :git => "https://github.com/robbdimitrov/RDVTabBarController.git", :tag => "v1.1.7" }
s.source = { :git => "https://github.com/robbdimitrov/RDVTabBarController.git", :tag => "v1.1.8" }
s.source_files = 'RDVTabBarController', 'RDVTabBarController/**/*.{h,m}'
s.framework = 'UIKit', 'CoreGraphics', 'Foundation'
s.requires_arc = true
Expand Down
6 changes: 6 additions & 0 deletions RDVTabBarController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
B44008F5180B185E00D8CB89 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = B44008F1180B185E00D8CB89 /* [email protected] */; };
B44008F6180B185E00D8CB89 /* third_selected.png in Resources */ = {isa = PBXBuildFile; fileRef = B44008F2180B185E00D8CB89 /* third_selected.png */; };
B44008F7180B185E00D8CB89 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = B44008F3180B185E00D8CB89 /* [email protected] */; };
B453D33A1A0E2219002F5656 /* RDVDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B453D3391A0E2219002F5656 /* RDVDetailsViewController.m */; };
B4616BAF17228DF700863892 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B4616BAE17228DF700863892 /* UIKit.framework */; };
B4616BB117228DF700863892 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B4616BB017228DF700863892 /* Foundation.framework */; };
B4616BB317228DF700863892 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B4616BB217228DF700863892 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -73,6 +74,8 @@
B44008F1180B185E00D8CB89 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
B44008F2180B185E00D8CB89 /* third_selected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = third_selected.png; sourceTree = "<group>"; };
B44008F3180B185E00D8CB89 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
B453D3381A0E2219002F5656 /* RDVDetailsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RDVDetailsViewController.h; sourceTree = "<group>"; };
B453D3391A0E2219002F5656 /* RDVDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RDVDetailsViewController.m; sourceTree = "<group>"; };
B4616BAB17228DF700863892 /* RDVTabBarController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RDVTabBarController.app; sourceTree = BUILT_PRODUCTS_DIR; };
B4616BAE17228DF700863892 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
B4616BB017228DF700863892 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -226,6 +229,8 @@
B465733C1725A24700319236 /* RDVSecondViewController.m */,
B465733E1725A25100319236 /* RDVThirdViewController.h */,
B465733F1725A25100319236 /* RDVThirdViewController.m */,
B453D3381A0E2219002F5656 /* RDVDetailsViewController.h */,
B453D3391A0E2219002F5656 /* RDVDetailsViewController.m */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -350,6 +355,7 @@
B4616C04172298FE00863892 /* main.m in Sources */,
B4616C0C1722995D00863892 /* RDVAppDelegate.m in Sources */,
B49817A617229BB500AD294C /* RDVTabBar.m in Sources */,
B453D33A1A0E2219002F5656 /* RDVDetailsViewController.m in Sources */,
B49817A917229CBC00AD294C /* RDVTabBarController.m in Sources */,
B465733A1725A23D00319236 /* RDVFirstViewController.m in Sources */,
B465733D1725A24700319236 /* RDVSecondViewController.m in Sources */,
Expand Down
17 changes: 8 additions & 9 deletions RDVTabBarController/RDVTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (void)viewWillAppear:(BOOL)animated {

[self setSelectedIndex:[self selectedIndex]];

[self setTabBarHidden:NO animated:NO];
[self setTabBarHidden:self.isTabBarHidden animated:NO];
}

- (NSUInteger)supportedInterfaceOrientations {
Expand Down Expand Up @@ -147,9 +147,11 @@ - (RDVTabBar *)tabBar {
if (!_tabBar) {
_tabBar = [[RDVTabBar alloc] init];
[_tabBar setBackgroundColor:[UIColor clearColor]];
[_tabBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|
UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin];
[_tabBar setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleTopMargin|
UIViewAutoresizingFlexibleLeftMargin|
UIViewAutoresizingFlexibleRightMargin|
UIViewAutoresizingFlexibleBottomMargin)];
[_tabBar setDelegate:self];
}
return _tabBar;
Expand All @@ -159,9 +161,8 @@ - (UIView *)contentView {
if (!_contentView) {
_contentView = [[UIView alloc] init];
[_contentView setBackgroundColor:[UIColor whiteColor]];
[_contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleLeftMargin|
UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin];
[_contentView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight)];
}
return _contentView;
}
Expand All @@ -177,8 +178,6 @@ - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated {
CGFloat contentViewHeight = viewSize.height;
CGFloat tabBarHeight = CGRectGetHeight([[weakSelf tabBar] frame]);

NSLog(@"viewSize = %@", NSStringFromCGSize(viewSize));

if (!tabBarHeight) {
tabBarHeight = 49;
}
Expand Down

0 comments on commit 29f8f75

Please sign in to comment.