我将如何在Google地图中为ios添加搜索栏

时间:2013-12-20 03:55:25

标签: ios google-maps uisearchbar

以下是添加地图和UISearchBar的代码,但我的搜索栏无法在视图中看到。

-(void)setCamera {
    camera = [GMSCameraPosition cameraWithLatitude:currentLatitude
                                     longitude:currentLongitude
                                          zoom:8];

    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    searchBar = [[UISearchBar alloc]initWithFrame:CGRectZero];
    searchBar.frame = CGRectMake(0, 10, 100, searchBar.frame.size.height);
    [mapView_ addSubview:searchBar];
    self.view = mapView_;
}

2 个答案:

答案 0 :(得分:1)

//create a search bar with 0 width and 0 height
searchBar = [[UISearchBar alloc]initWithFrame:CGRectZero];

//set the frame to 0 height because line above sets the height to zero.
searchBar.frame = CGRectMake(0, 10, 100, searchBar.frame.size.height);


//maybe something like this?
searchBar.frame = CGRectMake(0, 10, 100, 44);

答案 1 :(得分:0)

[mapView_ bringubViewToFront] 试试这个