-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabBarViewController.m
151 lines (114 loc) · 4.6 KB
/
TabBarViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// TabBarViewController.m
// Tumblr2
//
// Created by Kelly An on 7/1/14.
// Copyright (c) 2014 Kelly An. All rights reserved.
//
#import "TabBarViewController.h"
#import "HomeViewController.h"
#import "AccountViewController.h"
#import "TrendingViewController.h"
#import "LoginViewController.h"
#import "ComposeViewController.h"
#import "SearchViewController.h"
@interface TabBarViewController ()
@property (strong, nonatomic) SearchViewController * searchViewController;
@property (strong, nonatomic) AccountViewController * accountViewController;
@property (strong, nonatomic) TrendingViewController * trendingViewController;
@property (strong, nonatomic) HomeViewController * homeViewController;
@property (weak, nonatomic) IBOutlet UIImageView *exploreText;
@property (weak, nonatomic) IBOutlet UIView *contentView;
- (IBAction)onHomeButton:(id)sender;
- (IBAction)onSearchButton:(id)sender;
- (IBAction)onComposeButton:(id)sender;
- (IBAction)onAccountButton:(id)sender;
- (IBAction)onTrendingButton:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *searchButton;
@property (weak, nonatomic) IBOutlet UIButton *homeButton;
@property (weak, nonatomic) IBOutlet UIButton *trendingButton;
@property (weak, nonatomic) IBOutlet UIButton *accountButton;
@end
@implementation TabBarViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
//this code imbeds the home view controller within a navigation view controller.
self.homeViewController = [[HomeViewController alloc] init];
self.searchViewController = [[SearchViewController alloc] init];
self.trendingViewController = [[TrendingViewController alloc] init];
self.accountViewController = [[AccountViewController alloc] init];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.exploreText.center = CGPointMake(.5*185, 15+.5*108);
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
self.exploreText.center = CGPointMake(.5*185, 10+.5*108);
}completion:nil];
self.homeViewController.view.frame = self.contentView.frame;
[self.contentView addSubview:self.homeViewController.view];
self.homeButton.selected = YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onHomeButton:(id)sender {
//load the home vc
self.homeViewController.view.frame = self.contentView.frame;
[self.contentView addSubview:self.homeViewController.view];
//unselect all the others the home button
self.homeButton.selected = YES;
//unselect the rest.
self.searchButton.selected = NO;
self.trendingButton.selected = NO;
self.accountButton.selected = NO;
//show the explore text
self.exploreText.hidden = NO;
}
- (IBAction)onSearchButton:(id)sender {
//load the vc
self.searchViewController.view.frame = self.contentView.frame;
[self.contentView addSubview:self.searchViewController.view];
self.homeButton.selected = NO;
self.searchButton.selected = YES;
self.trendingButton.selected = NO;
self.accountButton.selected = NO;
//show the explore text
self.exploreText.hidden = YES;
}
- (IBAction)onComposeButton:(id)sender {
UIViewController *vc = [[ComposeViewController alloc] init];
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; //rise from below
[self presentViewController:vc animated:YES completion:nil];
}
- (IBAction)onAccountButton:(id)sender {
//load the vc
self.accountViewController.view.frame = self.contentView.frame;
[self.contentView addSubview:self.accountViewController.view];
self.homeButton.selected = NO;
self.searchButton.selected = NO;
self.trendingButton.selected = NO;
self.accountButton.selected = YES;
//show the explore text
self.exploreText.hidden = NO;
}
- (IBAction)onTrendingButton:(id)sender {
//load the vc
self.trendingViewController.view.frame = self.contentView.frame;
[self.contentView addSubview:self.trendingViewController.view];
self.homeButton.selected = NO;
self.searchButton.selected = NO;
self.trendingButton.selected = YES;
self.accountButton.selected = NO;
//show the explore text
self.exploreText.hidden = NO;
}
@end