未被調用的previewActionItems(強制觸摸操作)

[英]previewActionItems not getting called (Force touch action)


I am using below code to add force touch preview actions... Peek and pop view works great, only actions are not showing... Please help my code is not getting executed for some reason, take a look:

我正在使用下面的代碼添加強制觸摸預覽動作…Peek和pop view功能很好,只有動作沒有顯示…請幫助我的代碼沒有因為某些原因而被執行,看看:

- (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;

}

1 个解决方案

#1


14  

I was facing the same issue was was stuck for long.

我面臨着同樣的問題被困了很長時間。

The mistake that i did was adding this method in the Caller View Controller. DO NOT add this method in the caller view controller , add it in the called view controller instead.

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

For example if you are presenting View Controller B (called) on force touch of View Controller A(caller), then add this method to the View Controller B (called).

例如,如果您在強制觸摸視圖控制器A(調用方)時顯示視圖控制器B(調用方),那么將此方法添加到視圖控制器B(調用方)。

and was too obvious , because we are handling the button actions in View controller B.

太明顯了,因為我們正在處理視圖控制器B中的按鈕動作。

Hope it helps you. All the best.

希望它能幫助你。願一切都好!


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/02/29/7259b5a25d6595671e852ac2aebea784.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com