3D Touch peep and pop problem

I am trying to implement the peek and pop function in my application. But since I can’t test it, I would like to know if I am doing this correctly, I feel that something is wrong?

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location 
{
    NSLog(@"TEST");

    NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:location];

    if (indexPath) {
        UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath];
        NSDictionary *dict = [self.array objectAtIndex:indexPath.row];
        cell.textLabel.text = [dict objectForKey:@"name"];

        DetailViewController *previewController = [[DetailViewController alloc] init];
        //     previewController.content = content;

        previewingContext.sourceRect = cell.frame;

        return previewController;
    }

return nil;
}
+4
source share
3 answers

I am currently implementing this in our application, and it looks mostly correct. The problem I ran into is that the coordinates given to you in the location are relative to the UIViewController view, not the UITableView. Depending on your installation, they may be the same, but in my case I needed to convert the location to UITableView coordinates.

CGPoint convertedLocation = [self.view convertPoint:location toView:self.tableView];

, .

+6

- convertLocation .

.

CGPoint convertedLocation = [self.tableView convertPoint:location fromView:self.view];

NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:convertedLocation];
+1

You do not need to adjust the location if you registered PreviewDelegate with the correct source code. Therefore, instead of

[self registerForPreviewingWithDelegate:self sourceView:self.view];

You must register it as follows:

[self registerForPreviewingWithDelegate:self sourceView:self.tableView];

Then the location that you get from calling the delegate takes into account the / contentOffset scroll.

+1
source

Source: https://habr.com/ru/post/1608905/


All Articles