0

i am implementing 3d touch peek an pop feature in iOS.

This is the code i have written for one button

- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{

    UIViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];


    detailVC.preferredContentSize = CGSizeMake(0.0, 500.0);

    previewingContext.sourceRect = self.btnDetail.frame;

    return detailVC;
}

This is just for one button in that same view i have 4 other buttons which i want to apply 3d touch in the same class. How can i do this??

Aryan Kashyap
  • 121
  • 1
  • 12

1 Answers1

1

You can just check the location. For example:

- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
    if(CGRectContainsPoint(self.btnDetail.frame,location)){
        UIViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];


        detailVC.preferredContentSize = CGSizeMake(0.0, 500.0);

        previewingContext.sourceRect = self.btnDetail.frame;

        return detailVC;
    }
    if(CGRectContainsPoint(self.otherBtn.frame,location)){
        UIViewController *otherVC = [self.storyboard instantiateViewControllerWithIdentifier:@"other"];


        otherVC.preferredContentSize = CGSizeMake(0.0, 500.0);

        previewingContext.sourceRect = self.otherBtn.frame;

        return otherVC;
    }
    …
}
beyowulf
  • 15,101
  • 2
  • 34
  • 40