2
  1. 我如何使用panGestureRecognizer打開sideMenu如果我已經有在frontViewController一些其他的滑動手勢(在我的情況下,它是HomescreenViewController)? 我的frontViewController包含一個5頁的pageViewController.So左側刷卡和右側刷卡已爲pageViewController啓用。SWRevealViewController panGestureRecognizer與pageViewController的iOS(上刷卡側菜單)

    我用frontViewController的viewDidLoad中下面的代碼:

    _sideButton.target = self.revealViewController; 
    _sideButton.action = @selector(revealToggle:); 
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 
    [self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer]; 
    

    這與pageViewController向右掃沿着不會做的工作。 然後我用這個代碼:

    self.revealViewController.draggableBorderWidth = self.view.frame.size.width/2; 
    

    不過這也是沒有working.I現在用的是最新版本的SWRevealViewController 2.4.0

    這是我frontViewController的視圖層次。 HomescreenViewController> pagerView> PageviewController> listingViewController

  2. 而且,當側菜單出現,則frontviewController的部分是活動的,並且當我嘗試通過向左滑動到關閉側菜單,識別出它作爲pageviewcontroller滑動。我希望第一個問題的解決方案也能解決這個問題。

UPDATE(回答): 看接受的答案爲題號2 對於第一個問題,如果你遇到像我這樣的問題,只是創建向左寬度20個像素的看法使用下面的代碼並將panGestureRecognizer添加到此視圖(在viewWillAppear中)。

SWSwipeViewForPanGesture=[[UIView alloc]initWithFrame:CGRectMake(0, 0,20, self.view.frame.size.height)]; 
_SWSwipeViewForPanGesture.backgroundColor=[UIColor clearColor]; 
[self.view addSubview:_SWSwipeViewForPanGesture]; 
[_SWSwipeViewForPanGesture addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 

此外,我不得不在- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position方法這是一個委託method.So,你應該確認在viewDidLoad中委託添加以下代碼。

[_SWSwipeViewForPanGesture addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 
[self.view bringSubviewToFront:_SWSwipeViewForPanGesture]; 

多數民衆贊成it.It簡單的工作!

回答

4

解決方案對於第一個問題:

你不能在一個視圖中識別兩個滑動手勢。所以基本上,回答你的第一個問題是不可能的。您的pageview控制器中的SWRevealViewController無法刷卡。

解決方案對於第二個問題:

寫代碼HomescreenViewControllerViewDidLoad方法。

- (void)viewDidLoad 
{ 
SWRevealViewController * revealController=[[SWRevealViewController alloc]init]; 
    revealController = [self revealViewController]; 
    [self.view addGestureRecognizer:revealController.panGestureRecognizer]; 
     revealController.delegate=self; 
    [revealController panGestureRecognizer]; 

    [revealController tapGestureRecognizer]; 
    [btnSideMenu addTarget:revealController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside]; 

} 

後,在您HomescreenViewControllerSWRevealViewController此委託方法。

- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position 
{ 
    if (revealController.frontViewPosition == FrontViewPositionRight) 
    { 
     UIView *lockingView = [UIView new]; 
     lockingView.translatesAutoresizingMaskIntoConstraints = NO; 

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:revealController action:@selector(revealToggle:)]; 
     [lockingView addGestureRecognizer:tap]; 
     [lockingView addGestureRecognizer:revealController.panGestureRecognizer]; 
     [lockingView setTag:1000]; 
     [revealController.frontViewController.view addSubview:lockingView]; 


     lockingView.backgroundColor=[UIColor ClearColor]; 

     NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(lockingView); 

     [revealController.frontViewController.view addConstraints: 
     [NSLayoutConstraint constraintsWithVisualFormat:@"|[lockingView]|" 
               options:0 
               metrics:nil 
                views:viewsDictionary]]; 
     [revealController.frontViewController.view addConstraints: 
     [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[lockingView]|" 
               options:0 
               metrics:nil 
                views:viewsDictionary]]; 
     [lockingView sizeToFit]; 
    } 
    else 
     [[revealController.frontViewController.view viewWithTag:1000] removeFromSuperview]; 
} 

可能是,它會幫助你。

+0

感謝您的回答Bhumica.The第二個問題是solved.Is有對pageviewcontroller禁用rightswipe當指數爲零的方式嗎?或者,我們可以添加一個透明的視圖(像你剛纔那樣)對HomescreenViewController的左端並添加revealController.panGestureRecognizer它? – abhi1992

+0

在ipad splitviewcontroller,我看到了一個應用程序中,當我們的指數在0,滑動手勢的作品拿菜單來朝前面。 – abhi1992

+0

@ abhi1992但如果你會把透明視圖上瀏覽量的指數0比你會怎麼刷去到下一個頁面。? – BHUMICA

相關問題