Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for usage along with UINavigationController (only tested top mode) #6

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions MGSwipeTabBarController/MGSwipeTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Mark Glagola on 12/15/12.
// Copyright (c) 2012 Mark Glagola. All rights reserved.
//
// Edited by Cihat Gündüz (Dschee) on 12.07.14.
//

#import "MGSwipeTabBarController.h"
#import "UIViewController+MGSwipeTabBarController.h"
Expand All @@ -17,14 +19,25 @@ @implementation MGSwipeTabBarController
@synthesize scrollView = _scrollView, viewControllers = _viewControllers, selectedIndex = _selectedIndex, tabBar = _tabBar;

- (UIScrollView*) scrollView {
if (!_scrollView) {
if (!_scrollView) {

CGRect scrollframe = self.view.frame;
if (self.tabBar) {
CGRect tabBarFrame = self.tabBar.frame;
scrollframe.size.height -= tabBarFrame.size.height;
if (tabBarPosition == MGTabBarPositionTop) {
scrollframe.origin.y = tabBarFrame.size.height;

if (self.navigationController) {
scrollframe.size.height -= 44;
scrollframe.origin.y += 44;
}

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0) {
scrollframe.size.height -= 20;
scrollframe.origin.y += 20;
}

}else {
tabBarFrame.origin.y += scrollframe.size.height;
_tabBar.frame = tabBarFrame;
Expand All @@ -38,11 +51,21 @@ - (UIScrollView*) scrollView {
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.autoresizesSubviews = NO;
_scrollView.autoresizingMask = UIViewAutoresizingNone;

CGPoint offset = CGPointMake(0, 0);
if (self.navigationController) {
offset.y += 44;
}

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0) {
offset.y += 20;
}
_scrollView.contentOffset = offset;
}
return _scrollView;
}

- (void) setSelectedIndex:(NSUInteger)selectedIndex
- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
if (selectedIndex >= self.viewControllers.count)
return;
Expand All @@ -55,15 +78,15 @@ - (void) setSelectedIndex:(NSUInteger)selectedIndex
_selectedIndex = selectedIndex;
}

- (id) initWithViewControllers:(NSArray*)viewControllers {
- (id)initWithViewControllers:(NSArray*)viewControllers {
return [self initWithViewControllers:viewControllers tabBar:nil];
}

- (id) initWithViewControllers:(NSArray*)viewControllers tabBar:(MGSwipeTabBar*)tabBar {
- (id)initWithViewControllers:(NSArray*)viewControllers tabBar:(MGSwipeTabBar*)tabBar {
return [self initWithViewControllers:viewControllers tabBar:tabBar atPosition:MGTabBarPositionTop];
}

- (id) initWithViewControllers:(NSArray*)viewControllers tabBar:(MGSwipeTabBar*)tabBar atPosition:(MGTabBarPosition)position
- (id)initWithViewControllers:(NSArray*)viewControllers tabBar:(MGSwipeTabBar*)tabBar atPosition:(MGTabBarPosition)position
{
if (self = [super init]) {
_viewControllers = viewControllers;
Expand All @@ -74,10 +97,12 @@ - (id) initWithViewControllers:(NSArray*)viewControllers tabBar:(MGSwipeTabBar*)
return self;
}

- (void) viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];

[self.view addSubview:self.scrollView];

if (self.tabBar){
Expand Down Expand Up @@ -110,7 +135,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {


#pragma mark - MGSwipeTabBarDelegate methods
- (void) swipeTabBarDidSelectIndex:(NSUInteger)selectedIndex {
- (void)swipeTabBarDidSelectIndex:(NSUInteger)selectedIndex {
self.selectedIndex = selectedIndex;
}
@end