VisibleRegionViewController.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #if !defined(__has_feature) || !__has_feature(objc_arc)
  2. #error "This file requires ARC support."
  3. #endif
  4. #import "SDKDemos/Samples/VisibleRegionViewController.h"
  5. #import <GoogleMaps/GoogleMaps.h>
  6. static CGFloat kOverlayHeight = 140.0f;
  7. @implementation VisibleRegionViewController {
  8. GMSMapView *_mapView;
  9. UIView *_overlay;
  10. UIBarButtonItem *_flyInButton;
  11. }
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
  15. longitude:144.966085
  16. zoom:4];
  17. _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  18. // Enable my location button to show more UI components updating.
  19. _mapView.settings.myLocationButton = YES;
  20. _mapView.myLocationEnabled = YES;
  21. _mapView.padding = UIEdgeInsetsMake(0, 0, kOverlayHeight, 0);
  22. self.view = _mapView;
  23. // Create a button that, when pressed, causes an overlaying view to fly-in/out.
  24. _flyInButton = [[UIBarButtonItem alloc] initWithTitle:@"Toggle Overlay"
  25. style:UIBarButtonItemStylePlain
  26. target:self
  27. action:@selector(didTapFlyIn)];
  28. self.navigationItem.rightBarButtonItem = _flyInButton;
  29. CGRect overlayFrame = CGRectMake(0, -kOverlayHeight, 0, kOverlayHeight);
  30. _overlay = [[UIView alloc] initWithFrame:overlayFrame];
  31. _overlay.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
  32. _overlay.backgroundColor = [UIColor colorWithHue:0.0 saturation:1.0 brightness:1.0 alpha:0.5];
  33. [self.view addSubview:_overlay];
  34. }
  35. - (void)didTapFlyIn {
  36. UIEdgeInsets padding = _mapView.padding;
  37. [UIView animateWithDuration:2.0 animations:^{
  38. CGSize size = self.view.bounds.size;
  39. if (padding.bottom == 0.0f) {
  40. _overlay.frame = CGRectMake(0, size.height - kOverlayHeight, size.width, kOverlayHeight);
  41. _mapView.padding = UIEdgeInsetsMake(0, 0, kOverlayHeight, 0);
  42. } else {
  43. _overlay.frame = CGRectMake(0, _mapView.bounds.size.height, size.width, 0);
  44. _mapView.padding = UIEdgeInsetsZero;
  45. }
  46. }];
  47. }
  48. @end