-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTChildViewController.m
More file actions
155 lines (122 loc) · 3.44 KB
/
Copy pathSTChildViewController.m
File metadata and controls
155 lines (122 loc) · 3.44 KB
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
152
153
154
155
//
// STChildViewController.m
// STTest
//
// Created by 刘敏 on 16/5/30.
// Copyright © 2016年 深圳市轩腾华兴科技开发有限公司. All rights reserved.
//
#import "STChildViewController.h"
#import "STNavigationController.h"
@implementation STChildViewController
- (void)dealloc
{
if (self)
{
//取消延迟执行
[[STChildViewController class] cancelPreviousPerformRequestsWithTarget:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
STNavBarView *navbar = [[STNavBarView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [STNavBarView barSize].width, [STNavBarView barSize].height)];
_navbar = navbar;
_navbar.viewCtrlParent = self;
[self.view addSubview:_navbar];
//设置导航栏背景颜色
[self setNabbarBackgroundColor:[UIColor whiteColor]];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (_navbar && !_navbar.hidden)
{
[self.view bringSubviewToFront:_navbar];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
#pragma mark -
- (void)bringNavBarToTopmost
{
if (_navbar)
{
[self.view bringSubviewToFront:_navbar];
}
}
// 设置STNavBarView 颜色
- (void)setNabbarBackgroundColor:(UIColor *)color
{
if (_navbar) {
[_navbar setBackgroundColor:color];
}
}
- (void)hideNavBar:(BOOL)bIsHide
{
_navbar.hidden = bIsHide;
}
- (void)setNavBarTitle:(NSString *)strTitle
{
if (_navbar)
{
[_navbar setTitle:strTitle];
}
else{
NSLog(@"APP_ASSERT_STOP");
NSAssert1(NO, @" \n\n\n===== APP Assert. =====\n%s\n\n\n", __PRETTY_FUNCTION__);
}
}
- (void)setNavBarLeftBtn:(UIButton *)btn
{
if (_navbar)
{
[_navbar setLeftBtn:btn];
}
else{
NSLog(@"APP_ASSERT_STOP");
NSAssert1(NO, @" \n\n\n===== APP Assert. =====\n%s\n\n\n", __PRETTY_FUNCTION__);
}
}
- (void)setNavBarRightBtn:(UIButton *)btn
{
if (_navbar)
{
[_navbar setRightBtn:btn];
}
}
// 是否可右滑返回
- (void)navigationCanDragBack:(BOOL)canDragBack
{
if (self.navigationController)
{
[((STNavigationController *)(self.navigationController)) navigationCanDragBack:canDragBack];
}
}
// 重设scroll view的内容区域和滚动条区域
- (void)resetScrollView:(UIScrollView *)scrollView tabBar:(BOOL)hasTabBar
{
if (scrollView)
{
UIEdgeInsets inset = scrollView.contentInset;
UIEdgeInsets insetIndicator = scrollView.scrollIndicatorInsets;
CGPoint ptContentOffset = scrollView.contentOffset;
CGFloat fTopInset = 0.0f;
CGFloat fTopIndicatorInset = 0.0f;
CGFloat fBottomInset = hasTabBar ? Bottom_H : 0.0f;
fTopInset += NaviBar_H - StatusBar_H;
fTopIndicatorInset += NaviBar_H - StatusBar_H;
inset.top += fTopInset;
inset.bottom += fBottomInset;
[scrollView setContentInset:inset];
insetIndicator.top += fTopIndicatorInset;
insetIndicator.bottom += fBottomInset;
[scrollView setScrollIndicatorInsets:insetIndicator];
ptContentOffset.y -= fTopInset;
[scrollView setContentOffset:ptContentOffset];
}
}
@end