VisibleRegionViewController.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2016 Google Inc. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GoogleMapsDemos/Samples/VisibleRegionViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. static CGFloat kOverlayHeight = 140.0f;
  18. @implementation VisibleRegionViewController {
  19. GMSMapView *_mapView;
  20. UIView *_overlay;
  21. UIBarButtonItem *_flyInButton;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
  26. longitude:144.966085
  27. zoom:4];
  28. _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  29. // Enable my location button to show more UI components updating.
  30. _mapView.settings.myLocationButton = YES;
  31. _mapView.myLocationEnabled = YES;
  32. _mapView.padding = UIEdgeInsetsMake(0, 0, kOverlayHeight, 0);
  33. self.view = _mapView;
  34. // Create a button that, when pressed, causes an overlaying view to fly-in/out.
  35. _flyInButton = [[UIBarButtonItem alloc] initWithTitle:@"Toggle Overlay"
  36. style:UIBarButtonItemStylePlain
  37. target:self
  38. action:@selector(didTapFlyIn)];
  39. self.navigationItem.rightBarButtonItem = _flyInButton;
  40. CGRect overlayFrame = CGRectMake(0, -kOverlayHeight, 0, kOverlayHeight);
  41. _overlay = [[UIView alloc] initWithFrame:overlayFrame];
  42. _overlay.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
  43. _overlay.backgroundColor = [UIColor colorWithHue:0.0 saturation:1.0 brightness:1.0 alpha:0.5];
  44. [self.view addSubview:_overlay];
  45. }
  46. - (void)didTapFlyIn {
  47. UIEdgeInsets padding = _mapView.padding;
  48. [UIView animateWithDuration:2.0 animations:^{
  49. CGSize size = self.view.bounds.size;
  50. if (padding.bottom == 0.0f) {
  51. self->_overlay.frame =
  52. CGRectMake(0, size.height - kOverlayHeight, size.width, kOverlayHeight);
  53. self->_mapView.padding = UIEdgeInsetsMake(0, 0, kOverlayHeight, 0);
  54. } else {
  55. self->_overlay.frame = CGRectMake(0, self->_mapView.bounds.size.height, size.width, 0);
  56. self->_mapView.padding = UIEdgeInsetsZero;
  57. }
  58. }];
  59. }
  60. @end