FrameRateViewController.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/FrameRateViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. @interface FrameRateViewController ()
  18. @end
  19. @implementation FrameRateViewController {
  20. GMSMapView *_mapView;
  21. UITextView *_statusTextView;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. GMSCameraPosition *camera =
  26. [GMSCameraPosition cameraWithLatitude:-33.868 longitude:151.2086 zoom:6];
  27. _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  28. self.view = _mapView;
  29. // Add a display for the current frame rate mode.
  30. _statusTextView = [[UITextView alloc] init];
  31. _statusTextView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0);
  32. _statusTextView.text = @"";
  33. _statusTextView.textAlignment = NSTextAlignmentCenter;
  34. _statusTextView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8f];
  35. _statusTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  36. _statusTextView.editable = NO;
  37. [self.view addSubview:_statusTextView];
  38. [_statusTextView sizeToFit];
  39. // Add a button toggling through modes.
  40. self.navigationItem.rightBarButtonItem =
  41. [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
  42. target:self
  43. action:@selector(didTapNext)];
  44. [self updateStatus];
  45. }
  46. - (void)didTapNext {
  47. _mapView.preferredFrameRate = [self nextFrameRate];
  48. [self updateStatus];
  49. }
  50. + (NSString *)nameForFrameRate:(GMSFrameRate)frameRate {
  51. switch (frameRate) {
  52. case kGMSFrameRatePowerSave:
  53. return @"PowerSave";
  54. case kGMSFrameRateConservative:
  55. return @"Conservative";
  56. case kGMSFrameRateMaximum:
  57. return @"Maximum";
  58. }
  59. }
  60. - (GMSFrameRate)nextFrameRate {
  61. switch (_mapView.preferredFrameRate) {
  62. case kGMSFrameRatePowerSave:
  63. return kGMSFrameRateConservative;
  64. case kGMSFrameRateConservative:
  65. return kGMSFrameRateMaximum;
  66. case kGMSFrameRateMaximum:
  67. return kGMSFrameRatePowerSave;
  68. }
  69. }
  70. - (void)updateStatus {
  71. _statusTextView.text =
  72. [NSString stringWithFormat:@"Preferred frame rate: %@",
  73. [self.class nameForFrameRate:_mapView.preferredFrameRate]];
  74. }
  75. @end