2016-04-28 102 views
0

我在iOS中實現了三維觸摸查看彈出功能。3D觸摸到一個類中的多個按鈕

這是我有一個按鈕

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

這僅僅是在同一視圖中的一個按鈕編寫的代碼我有我想在同一類應用三維觸摸4個其他按鈕。我怎樣才能做到這一點??

回答

1

您可以檢查位置。例如:

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