2013-03-21 66 views
0

我有一個UIViewContoller與一些容器(子)UIiewsController。主要的UIViewController(MVC)包含:如何將觸摸事件傳遞給parentViewController?

  • 1)佔據MVC的整個視圖甲UICollectionView(它是上述mvc.view但低於所有其他控件)。
  • 2.),其顯示搜索選項(s1vc)
  • 3.)另一個類似於#2(s2vc)
  • 4.)另一個類似於#2(s3vc)

enter image description here一個UIViewController

我已經爲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但沒有運氣。仍然無法通過滑動切面視圖控制器所在的位置來滑動收集視圖。

任何想法?

回答

0

此處的解決方案是在parentViewController(我在此代碼中將其稱爲facetContainerView)中爲容器視圖添加另一個插座(使用IB),然後將其設置爲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); 

希望這可以幫助某些人。

相關問題