2013-11-16 3 views
3
#import "MyLocationViewController.h" 
#import <GoogleMaps/GoogleMaps.h> 


@interface MyLocationViewController() 

@end 

@implementation MyLocationViewController { 
    GMSMapView *mapView_; 
    CLLocationManager *locationManager; 
} 

- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 


    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

    [locationManager startUpdatingLocation]; 

    NSLog(@"Current identifier: %@", [[NSBundle mainBundle] bundleIdentifier]); 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView_.myLocationEnabled = YES; 

    self.view = mapView_; 

    //Add text field 
    UITextField *textField = [[UITextField alloc] init]; 
    textField.frame = CGRectMake(mapView_.bounds.size.width - 290, mapView_.bounds.size.height - 48, 180, 40); 
    textField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin; 
    textField.borderStyle = UITextBorderStyleRoundedRect; 
    textField.font = [UIFont systemFontOfSize:15]; 
    textField.placeholder = @"enToi UHMUH Bar Heya"; 
    textField.autocorrectionType = UITextAutocorrectionTypeNo; 
    textField.keyboardType = UIKeyboardTypeDefault; 
    textField.returnKeyType = UIReturnKeyDone; 
    textField.clearButtonMode = UITextFieldViewModeWhileEditing; 
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    textField.clearButtonMode = UITextFieldViewModeWhileEditing; 
    textField.delegate = self; 
    [mapView_ addSubview:textField]; 
    [mapView_ resignFirstResponder]; 
    [mapView_ bringSubviewToFront:textField]; 
    [textField becomeFirstResponder]; 



    //Add Send Chat Button to UI 
    UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    sendButton.frame = CGRectMake(mapView_.bounds.size.width - 100, mapView_.bounds.size.height - 48, 90, 40); 
    sendButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin; 
    [sendButton setTitle:@"Send" forState:UIControlStateNormal]; 
    [mapView_ addSubview:sendButton]; 


    // Creates a marker in the center of the map. 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.title = @"Sydney"; 
    marker.map = mapView_; 
} 


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
    return YES; 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    return YES; 
} 



#pragma mark - CLLocationManagerDelegate 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    NSLog(@"didFailWithError: %@", error); 
    UIAlertView *errorAlert = [[UIAlertView alloc] 
           initWithTitle:@"Error" 
           message:@"Failed to get your location!" 
           delegate:nil 
           cancelButtonTitle:@"OKAY" 
           otherButtonTitles:nil]; 
    [errorAlert show]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    CLLocation *currentLocation = [locations lastObject]; 

    NSLog(@"didUpdateLocations: %@", currentLocation); 

    if (currentLocation != nil) { 

     GMSCameraPosition *newSpot = [GMSCameraPosition cameraWithLatitude:currentLocation.coordinate.latitude 
                   longitude:currentLocation.coordinate.longitude 
                     zoom:6]; 
     [mapView_ setCamera:newSpot]; 

    } 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 



@end 

Вот мой файл заголовка:IOS Google Maps TextField не Реагирование

#import <UIKit/UIKit.h> 
#import <CoreLocation/CoreLocation.h> 

@interface MyLocationViewController : UIViewController <CLLocationManagerDelegate, UITextFieldDelegate> 

@property (nonatomic, retain) UITextField *textField; 

@end 

Я не использую Interface Builder. Когда приложение загружается, я вижу свое текстовое поле и кнопку. При нажатии кнопки кнопка переключается по умолчанию. Текстовое поле не редактируется - не удается вызвать клавиатуру, щелкнув по ней, тип can not и т. Д.

Я выполнил чей-то метод, чтобы определить, находится ли кадр вне границ его родительского представления, и он вернулся говоря, что это было вне пределов - но я не совсем уверен, как это решить.

ответ

-1

Попробуйте

[self.view addSubview: textField]; 

Вместо

[mapView_ addSubview:textField]; 

Это может помочь вам.

+0

Ничего не случилось –

6

В googleMapView есть BlockingGestureRecognizer, который блокирует все пользовательские ввод. не добавить текстовое поле на карту или удалить блокировщик:

// Remove the GMSBlockingGestureRecognizer of the GMSMapView. 
+ (void)removeGMSBlockingGestureRecognizerFromMapView:(GMSMapView *)mapView 
{ 
    if([mapView.settings respondsToSelector:@selector(consumesGesturesInView)]) { 
     mapView.settings.consumesGesturesInView = NO; 
    } 
    else { 
     for (id gestureRecognizer in mapView.gestureRecognizers) 
     { 
      if (![gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) 
      { 
       [mapView removeGestureRecognizer:gestureRecognizer]; 
      } 
     } 
    } 
} 
3

Добавить это, если вам необходимо включить сенсорный событие в UITextField

for (id gestureRecognizer in mapView_.gestureRecognizers) 
    { 
     NSLog(@"mapview recognizer %@",gestureRecognizer); 
     if (![gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) 
     { 
      [mapView_ removeGestureRecognizer:gestureRecognizer]; 
     } 
    } 
0

Добавить свой UITextField или UISearchbar, чтобы подвид из Mapview_

UISearchBar *search; 
search = [[UISearchBar alloc] init]; 
    [search setTintColor:[UIColor colorWithRed:233.0/255.0 
             green:233.0/255.0 
              blue:233.0/255.0 
             alpha:1.0]]; 
    search.frame = CGRectMake(50,20,self.view.frame.size.width-70,32); 
    search.delegate = self; 
    search.placeholder = @"MapView"; 
[mapView_ addSubview:search]; 

Добавить следующий метод файл .m

// Remove the GMSBlockingGestureRecognizer of the GMSMapView. 
+ (void)removeGMSBlockingGestureRecognizerFromMapView:(GMSMapView *)mapView 
{ 
    for (id gestureRecognizer in mapView.gestureRecognizers) 
    { 
     NSLog(@"mapview recognizer %@",gestureRecognizer); 
     if (![gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) 
     { 
      [mapView removeGestureRecognizer:gestureRecognizer]; 
     } 
    } 
} 

вызовов Этот метод с вашей точки зрения появится

- (void)viewWillAppear:(BOOL)animated { 
    [ViewController removeGMSBlockingGestureRecognizerFromMapView:mapView_]; 

} 

Теперь он будет работать, я получил тестирование только с этим кодом.

Смежные вопросы