gpt4 book ai didi

iOS 谷歌地图 textField 没有响应

转载 作者:可可西里 更新时间:2023-11-01 05:12:54 25 4
gpt4 key购买 nike

#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

这是我的头文件:

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

@interface MyLocationViewController : UIViewController <CLLocationManagerDelegate, UITextFieldDelegate>

@property (nonatomic, retain) UITextField *textField;

@end

我没有使用 Interface Builder。当应用程序加载时,我可以看到我的文本字段和按钮。该按钮在触摸时执行其默认切换行为。文本字段不可编辑 - 无法通过单击调出键盘,无法输入等。

我确实运行了某人的方法来确定一个框架是否超出了其父 View 的范围,但它返回说它超出了范围 - 但我不太确定如何解决这个问题。

最佳答案

googleMapView 有一个阻止所有用户输入的 BlockingGestureRecognizer。不要将文本字段添加到 map 或删除阻止程序:

// 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];
}
}
}
}

关于iOS 谷歌地图 textField 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20015266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com