3D 触摸 在 UITableViewCell 目标 C 代码上弹出.(用力触摸)



我需要使用力触摸在目标 C 中的UITableViewCell上启用Peek And Pop功能。并且还需要在窥视视图下显示一些操作,例如默认邮件应用程序。我是iOS的新手,请帮助我到达那里。

在具有操作的 TableViewCell 和集合视图单元格上的窥视和弹出效果

1(您应该将调用方视图控制器类称为UIViewController预览委托

@interface MyTableViewController ((

2(创建用于存储信息的@property。

@property (nonatomic, strong) id previewingContext;

3(在ViewDidLoad中调用forceTouchIntialize方法

- (void)viewDidLoad {
    [super viewDidLoad];
    [self forceTochIntialize];
}

4(检查力触摸是否可用

-(void)forceTouchIntialize{
    if ([self isForceTouchAvailable]) {
        self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.view];
    }
}
- (BOOL)isForceTouchAvailable {
    BOOL isForceTouchAvailable = NO;
    if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]) {
        isForceTouchAvailable = self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
    }
    return isForceTouchAvailable;
}

5(指定要预览的内容的视图控制器(用于PEEK(

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing> )previewingContext viewControllerForLocation:(CGPoint)location{
    CGPoint cellPostion = [yourTableView convertPoint:location fromView:self.view];
    NSIndexPath *path = yourTableView indexPathForRowAtPoint:cellPostion];
    if (path) {
        UITableViewCell *tableCell = [yourTableView 
cellForRowAtIndexPath:path];
//Pushing to a nib File
        PushViewController *previewController = [[PushViewController alloc] initWithNibName:@"PushViewController" bundle:nil];
//To Pass data to Preview ViewController
 //       id temp = [yourDataArray objectAtIndex:path.row];
//        PushViewController.anyObject=temp;     
   previewingContext.sourceRect = [self.view convertRect:tableCell.frame fromView: yourTableView
 ];        return previewController;
    }
    return nil;
}

6(深度按压中的弹出(用于流行(

-(void)previewingContext:(id )previewingContext commitViewController: (UIViewController *)viewControllerToCommit {
    [self.navigationController showViewController:viewControllerToCommit sender:nil];
}

7(当控制器被偷看并且你向上滑动时,如果你想添加像删除这样的按钮,存档将此方法添加到你的预览ViewContrller(在这个例子中" PushViewController"(

- (NSArray<id> *)previewActionItems {
    UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:@"delete" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
    }];
    UIPreviewAction *previewAction2 = [UIPreviewAction actionWithTitle:@"archive" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
    }];
    return @[previewAction1,previewAction2];
}

相关内容

  • 没有找到相关文章

最新更新