簡體   English   中英

iPhone:將視圖用作帶有關閉按鈕的透明覆蓋

[英]iPhone: Use a view as a transparent overlay with closing button

我有一個帶有三個條形按鈕的地圖,用於在地圖上顯示不同的標記。 如果單擊條形按鈕,則特定的標記會顯示在地圖上,效果很好。

現在,當我單擊帶有按鈕的條形按鈕以再次關閉該覆蓋並顯示標記(在背景中設置)后,我想顯示一個帶有標記說明的透明覆蓋圖(彈出窗口)。

條形按鈕的功能:

- (IBAction)routeTwo:(id)sender
{
    // The code for the overlay
    // ...

    // remove any annotations that exist
    [map removeAnnotations:map.annotations];  

    // Add any annotations which belongs to route 2
    [map addAnnotation:[self.mapAnnotations objectAtIndex:2]];
    [map addAnnotation:[self.mapAnnotations objectAtIndex:3]];
    [map addAnnotation:[self.mapAnnotations objectAtIndex:4]];
    [map addAnnotation:[self.mapAnnotations objectAtIndex:5]];
}

我嘗試了以下可能性:

1.使用模態視圖控制器

RouteDescriptionViewController *routeDescriptionView = [[RouteDescriptionViewController alloc] init];
    [self presentModalViewController:routeDescriptionView animated:YES];
    [routeDescriptionView release];

效果很好,但問題是:后台的地圖視圖不再可見(配置模式視圖的alpha值不會改變任何內容)。

2.添加RouteDescriptionView作為子視圖

RouteDescriptionViewController *routeDescriptionView = [[RouteDescriptionViewController alloc] init];
    [self.view addSubview:routeDescriptionView.view];
    [routeDescriptionView release];

也可以很好地工作,但是這里的問題是:我無法在子視圖上配置關閉按鈕來關閉/刪除子視圖(RouteDescriptionView)。

3.使用UIAlertView

可以按預期工作,但是UIAlert並不是真正可定制的,因此不適合我的需求。

任何想法如何實現這一目標?

如果使用選項2,則可以將UIButton的實例添加為routeDescriptionView的子視圖,並將該按鈕連接到routeDescriptionView的removeFromSuperview方法。

例如,在RouteDescriptionViewController的loadView或viewDidLoad方法中:

UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
[closeButton addTarget:[self view] action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:closeButton];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM