2010-05-04 74 views
2

我想要在地圖工具包註釋點出現彈出窗口,但在註釋視圖屬性中找不到使用rect方法調用uipopovercontroller的「rect」。如果在地圖工具箱上給出註釋,人們如何找到適當的「框架」?將uipopovercontroller的箭頭放在mapkit上的註釋點

爲了給保羅更多的信息,這裏是我的嘗試:我已經使用:

- (void)mapView:(MKMapView *)mapView2 annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{ 
    NSLog(@"annotationView..."); 
    MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager]; 
    int choice = 0; 
    for (NSMutableDictionary *locationDictionary in [myGizmoClass searchResultsForResortLocation]) 
    { 
     if([view.annotation.title isEqualToString:[locationDictionary objectForKey:@"name"]]) 
     { 

      DetailViewTableStyleController *controller = [[DetailViewTableStyleController alloc] initWithlocationData:[[myGizmoClass searchResultsForResortLocation] objectAtIndex:choice] nibName:@"DetailViewTableStyle" bundle:[NSBundle mainBundle]]; 

      controller.categoryCode = [locationDictionary objectForKey:@"category_code"] ; 

      //create a popover controller 
      popoverControllerDetail = [[UIPopoverController alloc] initWithContentViewController:controller]; 

      // set contentsize 
      [popoverControllerDetail setPopoverContentSize:CGSizeMake(320,480)]; 

      //present the popover view non-modal 

      [popoverControllerDetail presentPopoverFromRect:view.rightCalloutAccessoryView.frame inView:mapView2 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

      [controller release]; 
      break; 
     } 
     choice = choice + 1; 
    } 
} 

而且......我在MapView的邊緣獲得左上角一酥料餅。

有誰能告訴我爲什麼?我試圖讓它出現在pin/annotationview附近。

回答

7

好吧,

這是我發現的唯一的變通至今:

CGPoint annotationPoint = [mapView2 convertCoordinate:view.annotation.coordinate toPointToView:mapView2]; 
float boxDY=annotationPoint.y; 
float boxDX=annotationPoint.x; 
CGRect box = CGRectMake(boxDX,boxDY,5,5); 
UILabel *displayLabel = [[UILabel alloc] initWithFrame:box]; 


[popoverControllerDetail presentPopoverFromRect:displayLabel.frame inView:mapView2 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
[displayLabel release]; 

關於這個糟糕的是,我假裝把它以註釋的視圖。我只需獲取註解視圖(MKMapKit樣式座標)的annotation.coordinate並將座標轉換爲屏幕座標。然後,我創建一個uilabel(在屏幕上獲得一個框架結構的構造)放置在註釋視圖的位置。然後我告訴popovercontroller出現在該幀的位置。

這是踢球者。我不會將uilabel添加到mapView2。一旦popovercontroller吸引了我,我就簡單地釋放它。

黑客,但乾淨。

+5

你不需要UILabel。 'displayLabel.frame'只是返回一個CGRect,所以你可以直接使用'box'。 – 2010-11-11 16:38:43

+0

presentPopoverFromRect:inView:permittedArrowDirections:animated的問題是,如果彈出窗口的內容大小超過屏幕上的內容大小(例如 – 2012-06-06 05:44:34

1

如果您有MKAnnotationView,並且您暗示您這麼做,那麼您可以使用它的frame屬性,因爲它是UIView的子類。

+0

檢查我添加的新代碼以獲取更多信息Paul。我感謝你的幫助。 – Jann 2010-05-04 17:34:38

+0

您應該打印出兩個框架值;我懷疑你正在使用來自不匹配視圖的座標。使用convertRect:toView:確保它們匹配。 – 2010-05-04 20:19:55

1

沒有閱讀所有答覆...但我有類似的問題。當我點擊標註泡泡中的附件按鈕時,我想顯示一個彈出框。 這就是我解決我的問題的方法。

首先,我將地圖集中到我選擇的註釋中,我認爲在這種情況下總是一個好主意。然後,我實現具有固定大小的彈出窗口並將其放置在正確的位置(在我看來)。

這裏是我的代碼的一部分:

-(void)mapView:(MKMapView *)theMapView annotationView:(MKAnnotationView *)pin calloutAccessoryControlTapped:(UIControl *)control 
{ 
    UIViewController *detailController = [[detailedPinView alloc] initWithNibName:@"detailedPinView" 
                      bundle:nil 
                    annotationView:pin]; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 

     UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:detailController]; 
     [aPopover setDelegate:self]; 
     [aPopover setPopoverContentSize:CGSizeMake(320, 320) animated:YES]; 

     [detailController setPopover:aPopover]; 
     [detailController release]; 

     [mapView deselectAnnotation:pin.annotation animated:YES]; 

     self.popoverController = aPopover; 

     [mapView setCenterCoordinate:pin.annotation.coordinate animated:YES]; 

     [self.popoverController presentPopoverFromRect:CGRectMake(382,498,0,0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
    } 
    else 
    { 
     [self presentModalViewController: detailController animated:YES]; 
    } 


    [detailController release]; 
} 
+0

我用我認爲是更好的方式回答了我自己的問題。 mkannotation的座標然後我讓iPad iPhoneOS仍然能夠在彈出窗口的位置做出最佳決定,我認爲這對大多數情況會更好(閱讀iPhoneOS更新)..但是感謝您的回覆。 – Jann 2010-05-10 16:11:00

2

在這個線程與第一例子的問題是在調用presentPopoverFromRect:inView:permittedArrowDirections:動畫:. inView:參數的值不正確。它應該是view.rightCalloutAccessoryView。

也就是說,矩形的座標是相對於rightCalloutAccessoryView。

通過此更改,行爲將類似於地圖應用程序,看起來正確。

0

presentPopoverFromRect:inView:permittedArrowDirections:animated的問題是,如果彈出窗口的內容大小大於屏幕上的內容大小(例如,因爲註釋靠近屏幕的邊緣),系統將首先(至少部分)忽視矩形,並將箭頭的頂端放在視圖中間的某處。我已經做這種方式解決了這個:

self.popover = [[UIPopoverController alloc] initWithContentViewController:placeDetailViewController]; 

[self.popover presentPopoverFromRect:CGRectMake(0, 0, 29, 31) inView:view.rightCalloutAccessoryView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 

的rightCalloutAccessoryView通常一個詳細披露按鈕,它由31的大小爲29所以我做什麼,是一個由31長方形29創建,涵蓋了整個配件視圖。然後,我從配件視圖中呈現彈出式廣告。通過將29增加到40,彈出箭頭將位於標註氣泡之外,但前提是有足夠的空間在屏幕上顯示整個標註。如果沒有,箭頭將移動到泡泡內。爲了保持一致的界面,我將寬度保留爲29.