国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 導航欄無縫圓滑的隱藏 Navigationbar實例代碼

2020-07-26 02:37:15
字體:
來源:轉載
供稿:網友

1.ViewController

.m

- (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];}

頭部代理

@interface ViewController ()<UINavigationControllerDelegate>

代理方法

- (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

@property (nonatomic,strong) id popDelegate;

.m

- (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];}

頭部代理

@interface KKViewController ()<UIGestureRecognizerDelegate>

手勢代理方法

- (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,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭锦后旗| 华坪县| 哈密市| 慈利县| 灵寿县| 方山县| 房山区| 斗六市| 保定市| 玉门市| 贵定县| 宁城县| 长治市| 乌兰察布市| 嵩明县| 麻栗坡县| 鄂温| 庆城县| 新龙县| 衡阳市| 虎林市| 凤山市| 武宣县| 巴彦淖尔市| 朔州市| 都江堰市| 南澳县| 定结县| 怀柔区| 鄂托克前旗| 渝北区| 东乌珠穆沁旗| 手机| 璧山县| 云和县| 华宁县| 马公市| 车致| 和顺县| 桦南县| 蒙阴县|