欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android NavigationController 右滑手勢(shì)詳解

 更新時(shí)間:2015年08月18日 15:21:58   投稿:mrr  
目前蘋(píng)果手機(jī)在人機(jī)交互中盡力做到極致,在ios7中,新增了一個(gè)小小功能,用戶不用點(diǎn)擊右上角的返回按鈕,在屏幕左邊一滑,就會(huì)返回。下面給大家詳解Android NavigationController 右滑手勢(shì),需要的朋友可以參考下

蘋(píng)果一直都在人機(jī)交互中盡力做到極致,在iOS7中,新增加了一個(gè)小小的功能,也就是這個(gè)api:self.navigationController.interactivePopGestureRecognizer.enabled = YES;

這個(gè)api功能就是在NavigationController堆棧內(nèi)的UIViewController可以支持右滑手勢(shì),也就是不用點(diǎn)擊右上角的返回按鈕,輕輕在屏幕左邊一滑,屏幕就會(huì)返回,隨著ios設(shè)備屏幕的增大,這個(gè)小功能讓手指短,拇指大和手殘人士看到了福音。

這個(gè)功能是好,但是經(jīng)常我們會(huì)有需求定制返回按鈕,如果手動(dòng)定制了返回按鈕,這個(gè)功能將會(huì)失效,也就是自定義了navigationItem的leftBarButtonItem,那么這個(gè)手勢(shì)就會(huì)失效。

解決方法找到兩種

1.重新設(shè)置手勢(shì)的delegate

復(fù)制代碼 代碼如下:

self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

2.當(dāng)然你也可以自己響應(yīng)這個(gè)手勢(shì)的事件

復(fù)制代碼 代碼如下:

[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];

有更多方法以后繼續(xù)補(bǔ)充,這里可以根據(jù)自己需要進(jìn)行選擇,如果只是簡(jiǎn)單定制了返回按鈕,第一種最簡(jiǎn)單,一句代碼搞定。

問(wèn)題二:ios開(kāi)發(fā) 向右滑動(dòng)手勢(shì)實(shí)現(xiàn)返回.在NavigationController中如何設(shè)置

在navigationController中實(shí)現(xiàn)向右滑動(dòng) 返回功能

系統(tǒng)提供的backbarbuttonitem,不用添加任何代碼即可實(shí)現(xiàn)向右滑動(dòng)后退功能,但是往往要對(duì)按鈕修改樣式等時(shí),就需要自定義leftbarbuttonitem,此時(shí)向右滑動(dòng)即失效.通過(guò)下面方法即可解決該問(wèn)題.(本人親自實(shí)驗(yàn)過(guò))

主要是通過(guò)設(shè)置navigationController.interactivePopGestureRecognizer 此手勢(shì)的一些屬性,此手勢(shì)大家可以通過(guò)sdk查看說(shuō)明,這里不細(xì)說(shuō)

1. self.navigationController.interactivePopGestureRecognizer.enabled = YES | NO;      手勢(shì)有效與否

2. self.navigationController.interactivePopGestureRecognizer.delegate = self;               手勢(shì)的代理,一般會(huì)設(shè)置為self

1中的屬性,再viewcontroller中默認(rèn)的設(shè)置為YES,即手勢(shì)有效.按照2中的屬性設(shè)置后,當(dāng)前的viewcontroller即可以實(shí)現(xiàn)該向右滑動(dòng)后退功能,但是當(dāng)回到navigationController的rootView中再次做出向右滑動(dòng)時(shí),程序會(huì)有問(wèn)題(再次push子controller時(shí),程序卡在當(dāng)前界面無(wú)法跳轉(zhuǎn)).有效解決方案如下:

說(shuō)明:有兩個(gè)controllerA,B

navigationController的rootview設(shè)置為A,在A中點(diǎn)擊按鈕后push B.在A的 -(void)viewDidAppear:(BOOL)animated方法中加入self.navigationController.interactivePopGestureRecognizer.enabled = NO;代碼如下:
- (void)viewDidAppear:(BOOL)animated
{
  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;  //讓rootView禁止滑動(dòng)
  }
}

然后再B中的- (void)viewDidLoad方法中加入

- (void)viewDidLoad
{
  // 配置返回按鈕
  UIBarButtonItem * backItem = [self barButtonForImageNames:@[@"icon-返回", @"", @""] action:@selector(popBack)];
  backItem.title = @"";
  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
  }
  self.navigationItem.leftBarButtonItem = backItem;

  if ([[[UIDevice currentDevice] systemVersion] floatValue]
 >= 7.0) {

    self.navigationController.interactivePopGestureRecognizer.delegate = self; 
  }
}

這樣即可以保證再A中向右滑動(dòng)后再次pushB時(shí)不會(huì)卡在A界面.

再項(xiàng)目中大家一般會(huì)創(chuàng)建風(fēng)格統(tǒng)一的界面,一般都會(huì)創(chuàng)建一個(gè)基礎(chǔ)viewcontroller,再此viewcontroller擴(kuò)展一個(gè)配置leftbarbutton的方法,在該方法中加入B的viewDidLoad中的代碼,這樣在創(chuàng)建leftbarbutton的同時(shí),直接加了返回的操作(不用每個(gè)viewController中都加入這樣一段代碼).然后只在navigationController的rootView中加入A的(void)viewDidAppear:(BOOL)animated方法即可.

以上內(nèi)容是Android NavigationController 右滑手勢(shì)詳解,希望大家喜歡。

相關(guān)文章

最新評(píng)論