RADetailMapModel.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // RADetailMapModel.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/9/4.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RADetailMapModel.h"
  9. static const CGFloat SpaceWidth = 90.0f;
  10. static const CGFloat SpaceHeight = 38.0f;
  11. @implementation RADetailMapModel {
  12. CGFloat _height;
  13. }
  14. - (void)setLatlon:(NSString *)latlon {
  15. _latlon = latlon;
  16. if ([_latlon containsString:@","]) {
  17. NSArray *arr = [_latlon componentsSeparatedByString:@","];
  18. NSString *lat = [arr objectAtIndex:0];
  19. NSString *lon = [arr objectAtIndex:1];
  20. self.lat = lat;
  21. self.lon = lon;
  22. }
  23. }
  24. - (void)setLocation:(NSString *)location {
  25. _location = location;
  26. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  27. [self caculateValueHeight];
  28. });
  29. }
  30. - (CGFloat)height {
  31. if (_height <= 0) {
  32. [self caculateValueHeight];
  33. }
  34. return _height;
  35. }
  36. - (void)caculateValueHeight {
  37. if (self.location.length == 0) {
  38. return;
  39. }
  40. CGFloat w = self.width;
  41. if (w <= 0) {
  42. w = CGRectGetWidth([UIScreen mainScreen].bounds);
  43. }
  44. CGFloat h = [self.location boundingRectWithSize:CGSizeMake(w - SpaceWidth, FLT_MAX)
  45. options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
  46. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0f]}
  47. context:nil].size.height;
  48. CGFloat navBtnHeight = 30.0f;
  49. if (h < navBtnHeight) { // navigation button height
  50. h = navBtnHeight;
  51. }
  52. _height = h + SpaceHeight;
  53. if (_height < 100.0f) {
  54. _height = 100.0f;
  55. }
  56. }
  57. @end