服务器之家

服务器之家 > 正文

iOS 导航栏无缝圆滑的隐藏 Navigationbar实例代码

时间:2021-04-06 15:11     来源/作者:小圭哥

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实例代码

总结

以上所述是小编给大家介绍的ios 导航栏无缝圆滑的隐藏 navigationbar,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://www.cnblogs.com/wangkejia/archive/2017/11/17/7852934.html

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部