2016-02-29 76 views
3

我使用下面的代碼來添加強制觸摸預覽操作... Peek和彈出視圖很好,只有行動沒有顯示...請幫助我的代碼沒有得到執行一些理由,看看:previewActionItems not getting calling(Force touch action)

- (NSArray<id<UIPreviewActionItem>> *)previewActionItems { 

    if (_previewActions == nil) { 

     UIPreviewAction *rateAction = [UIPreviewAction actionWithTitle:@"Rate" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { 

      EmbededRateViewController *embededRVC = [[EmbededRateViewController alloc]initWithEmployerToRate:self.employersArray[0]]; 

      embededRVC.view.bounds = CGRectMake(0, 0, self.view.frame.size.width - 40, 210); 
      [embededRVC setPopinTransitionStyle:BKTPopinTransitionStyleSnap]; 

      BKTBlurParameters *blurParameters = [[BKTBlurParameters alloc] init]; 

      blurParameters.tintColor = [UIColor colorWithWhite:0 alpha:0.5]; 
      blurParameters.radius = 0.3f; // 0.3 
      [embededRVC setBlurParameters:blurParameters]; 
      [embededRVC setPopinTransitionDirection:BKTPopinTransitionDirectionTop]; 
      [self.collectionView setScrollEnabled:NO]; 
      [self presentPopinController:embededRVC animated:YES completion:^{ 
       NSLog(@"Popin presented !"); 
      }]; 
     }]; 

     UIPreviewAction *commentAction = [UIPreviewAction actionWithTitle:@"Comment" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { 

      NewCommentViewController *ncvc = [[NewCommentViewController alloc]initWithEmployer:self.employersArray[0]]; 
      [self presentViewController:ncvc animated:YES completion:nil]; 
     }]; 

     UIPreviewAction *reportAction = [UIPreviewAction actionWithTitle:@"Report" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { 

      ReportEmployerViewController *reportEmpVC = [[ReportEmployerViewController alloc]initWithEmployer:self.employersArray[0]]; 
      [self presentViewController:reportEmpVC animated:YES completion:nil]; 
     }]; 

     UIPreviewAction *cancelAction = 
     [UIPreviewAction actionWithTitle:@"Cancel" 
            style:UIPreviewActionStyleSelected 
           handler:^(UIPreviewAction *action, 
              UIViewController *previewViewController){ 

           }]; 

     _previewActions = @[commentAction, rateAction, reportAction, cancelAction]; 
    } 
    return _previewActions; 

} 

回答

13

我正面臨同樣的問題被卡長了。

我做的錯誤是在調用者視圖控制器中添加此方法。 不要在調用者視圖控制器中添加此方法,而是將其添加到調用的視圖控制器中。

例如,如果您在View Controller A(調用者)的強制觸摸中呈現View Controller B(調用),則將此方法添加到View Controller B(調用)中。

,是太明顯了,因爲我們正在處理的視圖控制器B.按鈕動作

希望它可以幫助你。 一切順利。

+2

感謝他做了這份工作 – miljan

+1

很高興幫助哥們:-) –