1.viewcontroller
.m
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
- (void)viewdidload {
[super viewdidload];
self.title = @"隐藏导航栏";
uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];
button.backgroundcolor = [uicolor lightgraycolor];
button.frame = cgrectmake(10, 100, 60, 30);
[button addtarget:self action:@selector(buttonclick) forcontrolevents:uicontroleventtouchupinside];
[self.view addsubview:button];
self.navigationcontroller.delegate = self;
}
- (void)buttonclick{
///跳转到kkviewcontroller
[self performseguewithidentifier:@"pusht" sender:nil];
}
|
头部代理
?| 1 |
@interface viewcontroller ()<uinavigationcontrollerdelegate>
|
代理方法
?| 1 2 3 4 5 6 7 8 9 10 |
- (void)navigationcontroller:(uinavigationcontroller *)navigationcontroller willshowviewcontroller:(uiviewcontroller *)viewcontroller animated:(bool)animated {
[self.navigationcontroller setnavigationbarhidden: [self hiddenbarvc: viewcontroller] animated: animated];
}
- (bool)hiddenbarvc:(uiviewcontroller *)viewcontroller {
bool needhidenaivgaionbar = no;
if ([viewcontroller iskindofclass: [kkviewcontroller class]]) {
needhidenaivgaionbar = yes;
}
return needhidenaivgaionbar;
}
|
2.kkviewcontroller(目标viewcontroller)
新建一个kkviewcontroller
.h
?| 1 |
@property (nonatomic,strong) id popdelegate;
|
.m
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |
- (void)viewdidload {
[super viewdidload];
self.title = @"第二个页面";
[self popset];
}
- (void)popset{
_popdelegate = self.navigationcontroller.interactivepopgesturerecognizer.delegate;
sel action = nsselectorfromstring(@"handlenavigationtransition:");
uipangesturerecognizer *poppangesture = [[uipangesturerecognizer alloc] initwithtarget:self.popdelegate action:action];
poppangesture.maximumnumberoftouches = 1;
poppangesture.delegate = self;
[self.view addgesturerecognizer: poppangesture];
}
|
头部代理
?| 1 |
@interface kkviewcontroller ()<uigesturerecognizerdelegate>
|
手势代理方法
?| 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 |
- (bool)gesturerecognizershouldbegin:(uipangesturerecognizer *)gesturerecognizer{
///【下面两个方法写一个】
///全屏拖动
cgpoint tragpoint = [gesturerecognizer translationinview:gesturerecognizer.view];
if (tragpoint.x <= 0){
return no;
}
else{
if (self.navigationcontroller.viewcontrollers.count <= 1){
return no;
}
else{
return yes;
}
}
// ///局部允许拖动
// cgpoint tragpoint = [gesturerecognizer locationinview:gesturerecognizer.view];
// nslog(@"x=%f;y=%f",tragpoint.x,tragpoint.y);
// if (tragpoint.x > 60){///拖动的范围
// return no;
// }
// else{
// if (self.navigationcontroller.viewcontrollers.count <= 1) {
// return no;
// }
// else{
// return yes;
// }
// }
}
|
效果图

总结
以上所述是小编给大家介绍的ios 导航栏无缝圆滑的隐藏 navigationbar,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://www.cnblogs.com/wangkejia/archive/2017/11/17/7852934.html








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。