From 537355e16da43f38c3678b72d4bc265cf2883753 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 25 May 2017 10:59:10 -0700 Subject: pairing debug code --- platform/ios/app/MBXTestViewController.h | 13 ++++ platform/ios/app/MBXTestViewController.m | 50 ++++++++++++++ platform/ios/app/MBXViewController.m | 29 ++++++++ platform/ios/ios.xcodeproj/project.pbxproj | 6 ++ platform/ios/src/MGLMapView.mm | 106 +++++++++++++++++------------ 5 files changed, 161 insertions(+), 43 deletions(-) create mode 100644 platform/ios/app/MBXTestViewController.h create mode 100644 platform/ios/app/MBXTestViewController.m diff --git a/platform/ios/app/MBXTestViewController.h b/platform/ios/app/MBXTestViewController.h new file mode 100644 index 0000000000..11a43ab315 --- /dev/null +++ b/platform/ios/app/MBXTestViewController.h @@ -0,0 +1,13 @@ +// +// MBXTestViewController.h +// ios +// +// Created by Justin R. Miller on 5/25/17. +// Copyright © 2017 Mapbox. All rights reserved. +// + +#import + +@interface MBXTestViewController : UIViewController + +@end diff --git a/platform/ios/app/MBXTestViewController.m b/platform/ios/app/MBXTestViewController.m new file mode 100644 index 0000000000..c664e9804b --- /dev/null +++ b/platform/ios/app/MBXTestViewController.m @@ -0,0 +1,50 @@ +// +// MBXTestViewController.m +// ios +// +// Created by Justin R. Miller on 5/25/17. +// Copyright © 2017 Mapbox. All rights reserved. +// + +#import "MBXTestViewController.h" + +#import + +@interface MBXTestViewController () + +@property (nonatomic) MGLMapView *mapView; + +@end + +@implementation MBXTestViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle darkStyleURLWithVersion:9]]; + [self.view addSubview:self.mapView]; + + NSLog(@"new map view: %p", self.mapView); + +// [self.mapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]]; +// +// double lat = 0; +// double lon = 0; +// NSMutableArray *annotations = [NSMutableArray array]; +// for (int i = 0; i < 10; i++) +// { +// MGLPointAnnotation *a = [MGLPointAnnotation new]; +// a.coordinate = CLLocationCoordinate2DMake(lat, lon); +// [annotations addObject:a]; +// lat += 5; +// lon += 10; +// } +// [self.mapView addAnnotations:annotations]; +} + +- (void)handleTap:(UITapGestureRecognizer *)tap +{ + self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden; +} + +@end diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index d3927374a7..ccdac626ab 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -7,6 +7,8 @@ #import "MBXUserLocationAnnotationView.h" #import "MBXEmbeddedMapViewController.h" +#import "MBXTestViewController.h" + #import #import @@ -148,10 +150,37 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { } } +- (void)present +{ + MBXTestViewController *vc = [[MBXTestViewController alloc] initWithNibName:nil bundle:nil]; +// UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; +// vc.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Dismiss" style:UIBarButtonItemStyleDone target:self action:@selector(dismiss)]; + [self presentViewController:/*nav*/vc animated:YES completion:nil]; + + [self performSelector:@selector(dismiss) withObject:nil afterDelay:2]; +} + +- (void)dismiss +{ + [self dismissViewControllerAnimated:YES completion:nil]; +} + - (void)viewDidLoad { [super viewDidLoad]; + + [self performSelector:@selector(present) withObject:nil afterDelay:2]; + + + + return; + + + + + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState:) name:UIApplicationWillEnterForegroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationWillTerminateNotification object:nil]; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index b6d422d0fc..34d219f7ee 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -445,6 +445,7 @@ DD4823761D94AE6C00EB71B7 /* line_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823731D94AE6C00EB71B7 /* line_filter_style.json */; }; DD4823771D94AE6C00EB71B7 /* numeric_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */; }; DD58A4C61D822BD000E1F038 /* MGLExpressionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */; }; + DD945C0E1ED747FB00AB8DB0 /* MBXTestViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD945C0D1ED747FB00AB8DB0 /* MBXTestViewController.m */; }; DD9BE4F71EB263C50079A3AF /* UIViewController+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */; }; DD9BE4F81EB263C50079A3AF /* UIViewController+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DD9BE4F61EB263C50079A3AF /* UIViewController+MGLAdditions.m */; }; DD9BE4F91EB263D20079A3AF /* UIViewController+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */; }; @@ -917,6 +918,8 @@ DD4823731D94AE6C00EB71B7 /* line_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = line_filter_style.json; sourceTree = ""; }; DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = numeric_filter_style.json; sourceTree = ""; }; DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLExpressionTests.mm; path = ../../darwin/test/MGLExpressionTests.mm; sourceTree = ""; }; + DD945C0C1ED747FB00AB8DB0 /* MBXTestViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXTestViewController.h; sourceTree = ""; }; + DD945C0D1ED747FB00AB8DB0 /* MBXTestViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXTestViewController.m; sourceTree = ""; }; DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+MGLAdditions.h"; sourceTree = ""; }; DD9BE4F61EB263C50079A3AF /* UIViewController+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+MGLAdditions.m"; sourceTree = ""; }; FA68F1481E9D656600F9F6C2 /* MGLFillExtrusionStyleLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFillExtrusionStyleLayer.h; sourceTree = ""; }; @@ -1179,6 +1182,8 @@ DA1DC9691CB6C6B7006E619F /* MBXOfflinePacksTableViewController.m */, DA1DC9531CB6C1C2006E619F /* MBXViewController.h */, DA1DC99A1CB6E064006E619F /* MBXViewController.m */, + DD945C0C1ED747FB00AB8DB0 /* MBXTestViewController.h */, + DD945C0D1ED747FB00AB8DB0 /* MBXTestViewController.m */, 632281DD1E6F855900D75A5D /* MBXEmbeddedMapViewController.h */, 632281DE1E6F855900D75A5D /* MBXEmbeddedMapViewController.m */, DA821D051CCC6D59007508D4 /* Main.storyboard */, @@ -2115,6 +2120,7 @@ DA1DC9991CB6E054006E619F /* MBXAppDelegate.m in Sources */, DA1DC96B1CB6C6B7006E619F /* MBXOfflinePacksTableViewController.m in Sources */, DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */, + DD945C0E1ED747FB00AB8DB0 /* MBXTestViewController.m in Sources */, DA1DC99B1CB6E064006E619F /* MBXViewController.m in Sources */, 40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */, 632281DF1E6F855900D75A5D /* MBXEmbeddedMapViewController.m in Sources */, diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index ed989459f5..89b6cddd24 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -656,21 +656,39 @@ public: _isWaitingForRedundantReachableNotification = NO; } +- (void)removeFromSuperview +{ + NSLog(@"removeFromSuperview"); + + [super removeFromSuperview]; +} + + - (void)dealloc { + NSLog(@"dealloc"); + [_reachability stopNotifier]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [_attributionButton removeObserver:self forKeyPath:@"hidden"]; - if (_isObservingTopLayoutGuide) { - [(NSObject *)self.viewControllerForLayoutGuides.topLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; - } - - if (_isObservingBottomLayoutGuide) { - [(NSObject *)self.viewControllerForLayoutGuides.bottomLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; - } +// if (_isObservingTopLayoutGuide) { +// [(NSObject *)self.viewControllerForLayoutGuides.topLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; +// } else { +// NSLog(@"not observing top!"); +// } +// +// if (_isObservingBottomLayoutGuide) { +// [(NSObject *)self.viewControllerForLayoutGuides.bottomLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; +// } else { +// NSLog(@"not observing bottom!"); +// } + +// NSLog(@"observing: %@", self.ob + + // Removing the annotations unregisters any outstanding KVO observers. NSArray *annotations = self.annotations; @@ -791,21 +809,21 @@ public: UIViewController *viewController = self.viewControllerForLayoutGuides; BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets; - if (useLayoutGuides && viewController.topLayoutGuide && !_isObservingTopLayoutGuide) { - [(NSObject *)viewController.topLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:(void *)&MGLLayoutGuidesUpdatedContext]; - _isObservingTopLayoutGuide = YES; - } else if (!useLayoutGuides && _isObservingTopLayoutGuide) { - [(NSObject *)viewController.topLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; - _isObservingTopLayoutGuide = NO; - } - - if (useLayoutGuides && viewController.bottomLayoutGuide && !_isObservingBottomLayoutGuide) { - [(NSObject *)viewController.bottomLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:(void *)&MGLLayoutGuidesUpdatedContext]; - _isObservingBottomLayoutGuide = YES; - } else if (!useLayoutGuides && _isObservingBottomLayoutGuide) { - [(NSObject *)viewController.bottomLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; - _isObservingBottomLayoutGuide = NO; - } +// if (useLayoutGuides && viewController.topLayoutGuide && !_isObservingTopLayoutGuide) { +// [(NSObject *)viewController.topLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:(void *)&MGLLayoutGuidesUpdatedContext]; +// _isObservingTopLayoutGuide = YES; +// } else if (!useLayoutGuides && _isObservingTopLayoutGuide) { +// [(NSObject *)viewController.topLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; +// _isObservingTopLayoutGuide = NO; +// } +// +// if (useLayoutGuides && viewController.bottomLayoutGuide && !_isObservingBottomLayoutGuide) { +// [(NSObject *)viewController.bottomLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:(void *)&MGLLayoutGuidesUpdatedContext]; +// _isObservingBottomLayoutGuide = YES; +// } else if (!useLayoutGuides && _isObservingBottomLayoutGuide) { +// [(NSObject *)viewController.bottomLayoutGuide removeObserver:self forKeyPath:@"bounds" context:(void *)&MGLLayoutGuidesUpdatedContext]; +// _isObservingBottomLayoutGuide = NO; +// } } - (BOOL)isOpaque @@ -835,6 +853,8 @@ public: // This gets called when the view dimension changes, e.g. because the device is being rotated. - (void)layoutSubviews { + NSLog(@"layoutSubviews"); + [super layoutSubviews]; [self adjustContentInset]; @@ -933,27 +953,27 @@ public: UIViewController *viewController = self.viewControllerForLayoutGuides; BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets; - if (!_isObservingTopLayoutGuide && useLayoutGuides && viewController.topLayoutGuide) - { - [(NSObject *)viewController.topLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:MGLLayoutGuidesUpdatedContext]; - _isObservingTopLayoutGuide = YES; - } - else if (!useLayoutGuides && _isObservingTopLayoutGuide) - { - [(NSObject *)viewController.topLayoutGuide removeObserver:self forKeyPath:@"bounds" context:MGLLayoutGuidesUpdatedContext]; - _isObservingTopLayoutGuide = NO; - } - - if (!_isObservingBottomLayoutGuide && useLayoutGuides && viewController.bottomLayoutGuide) - { - [(NSObject *)viewController.bottomLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:MGLLayoutGuidesUpdatedContext]; - _isObservingBottomLayoutGuide = YES; - } - else if (!useLayoutGuides && _isObservingBottomLayoutGuide) - { - [(NSObject *)viewController.bottomLayoutGuide removeObserver:self forKeyPath:@"bounds" context:MGLLayoutGuidesUpdatedContext]; - _isObservingBottomLayoutGuide = NO; - } +// if (!_isObservingTopLayoutGuide && useLayoutGuides && viewController.topLayoutGuide) +// { +// [(NSObject *)viewController.topLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:MGLLayoutGuidesUpdatedContext]; +// _isObservingTopLayoutGuide = YES; +// } +// else if (!useLayoutGuides && _isObservingTopLayoutGuide) +// { +// [(NSObject *)viewController.topLayoutGuide removeObserver:self forKeyPath:@"bounds" context:MGLLayoutGuidesUpdatedContext]; +// _isObservingTopLayoutGuide = NO; +// } +// +// if (!_isObservingBottomLayoutGuide && useLayoutGuides && viewController.bottomLayoutGuide) +// { +// [(NSObject *)viewController.bottomLayoutGuide addObserver:self forKeyPath:@"bounds" options:0 context:MGLLayoutGuidesUpdatedContext]; +// _isObservingBottomLayoutGuide = YES; +// } +// else if (!useLayoutGuides && _isObservingBottomLayoutGuide) +// { +// [(NSObject *)viewController.bottomLayoutGuide removeObserver:self forKeyPath:@"bounds" context:MGLLayoutGuidesUpdatedContext]; +// _isObservingBottomLayoutGuide = NO; +// } } - (void)setContentInset:(UIEdgeInsets)contentInset -- cgit v1.2.1