2

マップキットの注釈ポイントにポップオーバーを表示しようとしていますが、注釈ビューのプロパティでuipopovercontrollerを呼び出すrectメソッドを使用するための「rect」が見つかりません。マップキットに注釈が付けられている場合、適切な「フレーム」をどのように見つけるのでしょうか。

ポールにもっと情報を与えるために、ここに私の試みがあります:私はすでに使用しました:

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

そして...マップビューの端の左上にポップオーバーが表示されます。

誰か教えてもらえますか?pin/annotationviewの近くに表示させようとしています。

4

5 に答える 5

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 を取得し、座標を画面座標に変換するだけです。次に、Annotation View が配置される場所に uilabel を作成します (画面上でフレーム対応の構造を取得するため)。次に、popovercontroller にそのフレーム位置に表示されるように指示します。

これがキッカーです。mapView2 に uilabel を追加しません。popovercontroller が自分自身を描画したら、単純に解放します。

ハックしますが、クリーンです。

于 2010-05-04T21:13:59.227 に答える
2

このスレッドの最初の例の問題は、presentPopoverFromRect:inView:permittedArrowDirections:animated: の呼び出しにあります。inView: パラメータの値が正しくありません。それは、view.rightCalloutAccessoryView である必要があります。

つまり、長方形の座標は rightCalloutAccessoryView に相対的です。

この変更により、動作は正しいと思われるマップ アプリケーションに似たものになります。

于 2010-06-26T14:40:25.483 に答える
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];
}
于 2010-05-09T20:57:49.553 に答える
1

を持っていてMKAnnotationView、それを暗示している場合は、サブクラスであるため、そのframeプロパティを使用できます。UIView

于 2010-05-04T07:27:51.987 に答える
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 は、通常、サイズが 29 x 31 の詳細開示ボタンです。そこで、アクセサリ ビュー全体をカバーする 29 x 31 の長方形を作成します。次に、アクセサリ ビューからポップオーバーを表示します。29 を 40 に増やすと、吹き出しの吹き出しの外側にポップオーバー矢印が表示されますが、吹き出し全体を画面に表示するのに十分なスペースがある場合に限ります。そうでない場合、矢印はバブル内に移動します。一貫したインターフェイスを維持するために、幅を 29 のままにしました。

于 2012-06-06T05:57:33.100 に答える