右侧使用 SWRevealViewController 的两个面板

Posted

技术标签:

【中文标题】右侧使用 SWRevealViewController 的两个面板【英文标题】:Two Panels on the Right Using SWRevealViewController 【发布时间】:2014-06-27 12:09:57 【问题描述】:

我已经用单指平移手势成功地在右侧创建了一个面板。当用户使用两指手势滑动时,我必须在同一侧显示另一个视图控制器。我尝试在 SWRevealViewController.h 类文件中添加它,但它不起作用。我创建了两个不同的序列和 sw_right 和 sw_test .. 如果用户滑动一根手指,将显示 SW_right 序列的视图控制器,如果用户滑动两个手指序列,则应显示 SW_test 序列。请帮助我在这里感到震惊。下面是我的代码

static NSString * const SWSegueRearIdentifier = @"sw_rear";
static NSString * const SWSegueFrontIdentifier = @"sw_front";
static NSString * const SWSegueRightIdentifier = @"sw_right";
static NSString * const SWSegueRightIdentifier2 =@"sw_test"; // mytest

- (void)prepareForSegue:(SWRevealViewControllerSegue *)segue sender:(id)sender

    // $ using a custom segue we can get access to the storyboard-loaded rear/front view controllers
    // the trick is to define segues of type SWRevealViewControllerSegue on the storyboard
    // connecting the SWRevealViewController to the desired front/rear controllers,
    // and setting the identifiers to "sw_rear" and "sw_front"

    // $ these segues are invoked manually in the loadView method if a storyboard
    // was used to instantiate the SWRevealViewController

    // $ none of this would be necessary if Apple exposed "relationship" segues for container view controllers.

    NSString *identifier = segue.identifier;
    if ( [segue isKindOfClass:[SWRevealViewControllerSegue class]] && sender == nil )
    
        if ( [identifier isEqualToString:SWSegueRearIdentifier] )
        
            segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
            
                [self _setRearViewController:dvc animated:NO];
            ;
        
        else if ( [identifier isEqualToString:SWSegueFrontIdentifier] )
        
            segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
            
                [self _setFrontViewController:dvc animated:NO];
            ;
        
        else if ( [identifier isEqualToString:SWSegueRightIdentifier] )
        
            segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
            
                [self _setRightViewController:dvc animated:NO];
            ;
        
        //mytest code
        **else if ( [identifier isEqualToString:SWSegueRightIdentifier2] )
        
            segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
            
                [self _setRightViewController:dvc animated:NO];
            ;
        **
        //code test

    

【问题讨论】:

【参考方案1】:

最后我找到了一个拥有两个面板的解决方案。我只是使用一个控制器根据执行的触摸显示两个不同的数据。这就是我所做的。我在显示视图控制器中编写了这段代码

-(void)viewWillAppear:(BOOL)animated

     int numberofTouches =  self.revealViewController.panGestureRecognizer.numberOfTouches;
    NSLog(@"%d",numberofTouches);
    if (numberofTouches ==1) 
        numberOfTouchesString=@"One";
    
    else if (numberofTouches==2)
    
        numberOfTouchesString=@"Two";
    
    [learningSearchTableView reloadData];



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    if ([numberOfTouchesString isEqualToString:@"One"]) 
        return 6;
    
    else if ([numberOfTouchesString isEqualToString:@"Two"])
    
        return 5;
    
    else
        return 0;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    NSLog(@"selected");
    if ([numberOfTouchesString isEqualToString:@"One"]) 
        NSLog(@"%@",indexPath);

    
    else if ([numberOfTouchesString isEqualToString:@"Two"])
    
        NSLog(@"The other %@",indexPath);
    


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    static NSString *cellIdentifier = @"learningSearchCellIdentifier";
    LearningSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];


    if ([numberOfTouchesString isEqualToString:@"One"]) 
      cell.subjectNameLabel.text=@"ART";
        cell.subjecDataAndSessionLabel.text=@"Friday 11th April - LS3(Cohort 11)";
        cell.teacherNameLabel.text=@"Mr Starr";

    
    else if ([numberOfTouchesString isEqualToString:@"Two"])
    
        cell.subjectNameLabel.text=@"English";
        cell.subjecDataAndSessionLabel.text=@"Sunday 12th April - LS3(Cohort 11)";
        cell.teacherNameLabel.text=@"Mr Harry";


    
    return cell;



【讨论】:

以上是关于右侧使用 SWRevealViewController 的两个面板的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 jqueryui 仅在其右侧调整左侧 div 的大小,并且它是相邻的右侧 div,仅在其左侧?

右侧使用 SWRevealViewController 的两个面板

使用 CSS 从右侧偏移背景图像

使用 cut 命令从右侧提取的代码?

如何使用 GitHub markdown 在图像右侧写入文本

如何在不使用重力属性的情况下移动右侧的第一列?