0

我有一个带有几个容器(子)UIiewsController 的 UIViewContoller。主 UIViewController (mvc) 包含:

  • 1.) 占据整个 mvc 视图的 UICollectionView(它在 mvc.view 之上但在所有其他控件之下)。
  • 2.) 显示搜索选项的 UIViewController (s1vc)
  • 3.) 另一个类似于 #2 (s2vc)
  • 4.) 另一个类似于 #2 (s3vc)

在此处输入图像描述

我在 mvc 中添加了手势识别器,以便用户可以通过将每个子视图控制器从屏幕上滑出来隐藏/显示它们。

问题是当用户从屏幕上滑出任何 svcs 时,他们无法滚动 mvc 的 collectionView。

这是我隐藏/显示 svcs 的方式:

-(void)swipeLeftGestureHandler:(UIGestureRecognizer*)gestureRecognizer{
    SMLOG(@"Swiped Left");
    if([SMUser activeUser] == nil) return;
    if([self gestureHorizontalScreenSide:gestureRecognizer] == kHorizontalScreenSideLeft){
        [self hideFacets];
    }
    else{
        [self showAccordion];
    }
}
-(void)swipeRightGestureHandler:(UIGestureRecognizer*)gestureRecognizer{
    SMLOG(@"Swiped Right");
    if([SMUser activeUser] == nil) return;
    if([self gestureHorizontalScreenSide:gestureRecognizer] == kHorizontalScreenSideLeft){
        [self showFacets];
    }
    else{
        [self hideAccordion];
    }
}

-(void)hideFacets{
    if(self.facetVisible == NO) return;

    [UIView animateWithDuration:0.25
                     animations:^{
                         CGRect newFrame = self.facetViewController.view.frame;
                         newFrame.origin = CGPointMake(newFrame.origin.x - newFrame.size.width, newFrame.origin.y);
                         self.facetViewController.view.frame = newFrame;
                         self.facetVisible = NO;
                     }
                     completion:^(BOOL finished){
                         self.facetViewController.view.hidden = YES;
                         self.facetViewController.view.userInteractionEnabled = NO;
                     }];
}

-(void)showFacets{
    if([SMUser activeUser] == nil) return;
    if(self.facetVisible == YES) return;

    self.facetViewController.view.userInteractionEnabled = YES;
    [UIView animateWithDuration:0.25
                     animations:^{
                         self.facetViewController.view.hidden = NO;
                         CGRect newFrame = self.facetViewController.view.frame;
                         newFrame.origin = CGPointMake(newFrame.origin.x + newFrame.size.width, newFrame.origin.y);
                         self.facetViewController.view.frame = newFrame;
                         self.facetVisible = YES;
                     }
                     completion:^(BOOL finished){         
                     }];
}

如您所见,我正在切换 svc.view.hidden 属性,然后我也尝试切换 svc.userInteractionEnabled.property 但没有运气。仍然无法通过滑动构面视图控制器所在的位置来滑动集合视图。

有任何想法吗?

4

1 回答 1

0

这里的解决方案是在 parentViewController 中为容器视图添加另一个插座(使用 IB)(我在此代码中将其称为 facetContainerView),然后将其设置为 userInteractionEnabled 属性。

-(void)hideFacets{
    if(self.facetVisible == NO) return;
    self.facetVisible = NO;

    [UIView animateWithDuration:0.25
                     animations:^{
                         CGRect newFrame = self.facetViewController.view.frame;
                         newFrame.origin = CGPointMake(newFrame.origin.x - newFrame.size.width, newFrame.origin.y);
                         self.facetViewController.view.frame = newFrame;
                     }
                     completion:^(BOOL finished){
                         self.facetViewController.view.hidden = YES;
                         self.facetContainerView.userInteractionEnabled = NO;
                     }];
}

-(void)showFacets{
    if(self.facetVisible == YES) return;
    self.facetVisible = YES;
    self.facetContainerView.userInteractionEnabled = YES;

    [UIView animateWithDuration:0.25
                     animations:^{
                         self.facetViewController.view.hidden = NO;
                         CGRect newFrame = self.facetViewController.view.frame;
                         newFrame.origin = CGPointMake(newFrame.origin.x + newFrame.size.width, newFrame.origin.y);
                         self.facetViewController.view.frame = newFrame;
                     }
                     completion:^(BOOL finished){         
                     }];
}

我很好奇这个新的视图出口与 self.facetViewController.view 有何不同,所以我插入了这段代码来比较地址(它们确实不同)。我不确定层次结构,但似乎还有一个我不知道的额外视图层。

NSLog(@"self.facetViewController.view: %p", self.facetViewController.view);
NSLog(@"self.facetContainerView: %p", self.facetContainerView);

希望这会在某个时候对某人有所帮助。

于 2013-04-17T22:37:51.433 回答