From a65730803e4185600ff7251cf0a18a4835f4f41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 3 Mar 2016 16:33:25 -0800 Subject: [PATCH] [ios] Converted iosapp to use storyboard --- platform/ios/app/MBXAppDelegate.m | 4 - platform/ios/app/MBXViewController.mm | 112 ++++++++----------------- platform/ios/app/Storyboard.storyboard | 97 +++++++++++++++++++++ platform/ios/app/app-info.plist | 2 + platform/ios/app/mapboxgl-app.gypi | 1 + 5 files changed, 136 insertions(+), 80 deletions(-) create mode 100644 platform/ios/app/Storyboard.storyboard diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m index a06424feb..9ceee7cad 100644 --- a/platform/ios/app/MBXAppDelegate.m +++ b/platform/ios/app/MBXAppDelegate.m @@ -23,10 +23,6 @@ [MGLAccountManager setAccessToken:accessToken]; } - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[MBXViewController new]]; - [self.window makeKeyAndVisible]; - return YES; } diff --git a/platform/ios/app/MBXViewController.mm b/platform/ios/app/MBXViewController.mm index af4e42584..548a5e710 100644 --- a/platform/ios/app/MBXViewController.mm +++ b/platform/ios/app/MBXViewController.mm @@ -19,7 +19,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { @interface MBXViewController () -@property (nonatomic) MGLMapView *mapView; +@property (nonatomic) IBOutlet MGLMapView *mapView; @property (nonatomic) NSUInteger styleIndex; @end @@ -44,94 +44,54 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { } } -- (id)init -{ - self = [super init]; - - if (self) - { - [[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]; - } - - return self; -} - - (void)viewDidLoad { [super viewDidLoad]; - - self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds]; - self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - self.mapView.delegate = self; - [self.view addSubview:self.mapView]; - - self.view.tintColor = kTintColor; - self.navigationController.navigationBar.tintColor = kTintColor; - self.mapView.tintColor = kTintColor; - - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"settings.png"] - style:UIBarButtonItemStylePlain - target:self - action:@selector(showSettings)]; + [[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]; + self.styleIndex = 0; - UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [titleButton setFrame:CGRectMake(0, 0, 150, 40)]; + UIButton *titleButton = (UIButton *)self.navigationItem.titleView; [titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal]; - [titleButton setTitleColor:kTintColor forState:UIControlStateNormal]; - [titleButton addTarget:self action:@selector(cycleStyles) forControlEvents:UIControlEventTouchUpInside]; - self.navigationItem.titleView = titleButton; - - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"TrackingLocationOffMask.png"] - style:UIBarButtonItemStylePlain - target:self - action:@selector(locateUser)]; - - [self.mapView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]]; [self restoreState:nil]; } - (void)saveState:(__unused NSNotification *)notification { - if (self.mapView) - { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSData *archivedCamera = [NSKeyedArchiver archivedDataWithRootObject:self.mapView.camera]; - [defaults setObject:archivedCamera forKey:@"MBXCamera"]; - [defaults setInteger:self.mapView.userTrackingMode forKey:@"MBXUserTrackingMode"]; - [defaults setBool:self.mapView.showsUserLocation forKey:@"MBXShowsUserLocation"]; - [defaults setInteger:self.mapView.debugMask forKey:@"MBXDebugMask"]; - [defaults synchronize]; - } + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSData *archivedCamera = [NSKeyedArchiver archivedDataWithRootObject:self.mapView.camera]; + [defaults setObject:archivedCamera forKey:@"MBXCamera"]; + [defaults setInteger:self.mapView.userTrackingMode forKey:@"MBXUserTrackingMode"]; + [defaults setBool:self.mapView.showsUserLocation forKey:@"MBXShowsUserLocation"]; + [defaults setInteger:self.mapView.debugMask forKey:@"MBXDebugMask"]; + [defaults synchronize]; } - (void)restoreState:(__unused NSNotification *)notification { - if (self.mapView) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSData *archivedCamera = [defaults objectForKey:@"MBXCamera"]; - MGLMapCamera *camera = archivedCamera ? [NSKeyedUnarchiver unarchiveObjectWithData:archivedCamera] : nil; - if (camera) - { - self.mapView.camera = camera; - } - NSInteger uncheckedTrackingMode = [defaults integerForKey:@"MBXUserTrackingMode"]; - if (uncheckedTrackingMode >= 0 && - (NSUInteger)uncheckedTrackingMode >= MGLUserTrackingModeNone && - (NSUInteger)uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse) - { - self.mapView.userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode; - } - self.mapView.showsUserLocation = [defaults boolForKey:@"MBXShowsUserLocation"]; - NSInteger uncheckedDebugMask = [defaults integerForKey:@"MBXDebugMask"]; - if (uncheckedDebugMask >= 0) - { - self.mapView.debugMask = (MGLMapDebugMaskOptions)uncheckedDebugMask; - } + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSData *archivedCamera = [defaults objectForKey:@"MBXCamera"]; + MGLMapCamera *camera = archivedCamera ? [NSKeyedUnarchiver unarchiveObjectWithData:archivedCamera] : nil; + if (camera) + { + self.mapView.camera = camera; + } + NSInteger uncheckedTrackingMode = [defaults integerForKey:@"MBXUserTrackingMode"]; + if (uncheckedTrackingMode >= 0 && + (NSUInteger)uncheckedTrackingMode >= MGLUserTrackingModeNone && + (NSUInteger)uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse) + { + self.mapView.userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode; + } + self.mapView.showsUserLocation = [defaults boolForKey:@"MBXShowsUserLocation"]; + NSInteger uncheckedDebugMask = [defaults integerForKey:@"MBXDebugMask"]; + if (uncheckedDebugMask >= 0) + { + self.mapView.debugMask = (MGLMapDebugMaskOptions)uncheckedDebugMask; } } @@ -142,7 +102,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { #pragma mark - Actions -- (void)showSettings +- (IBAction)showSettings:(__unused id)sender { MGLMapDebugMaskOptions debugMask = self.mapView.debugMask; UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Map Settings" @@ -441,7 +401,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { [self.mapView showAnnotations:@[annotation] animated:YES]; } -- (void)handleLongPress:(UILongPressGestureRecognizer *)longPress +- (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress { if (longPress.state == UIGestureRecognizerStateBegan) { @@ -455,7 +415,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { } } -- (void)cycleStyles +- (IBAction)cycleStyles:(__unused id)sender { UIButton *titleButton = (UIButton *)self.navigationItem.titleView; @@ -466,7 +426,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { [titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal]; } -- (void)locateUser +- (IBAction)locateUser:(__unused id)sender { MGLUserTrackingMode nextMode; switch (self.mapView.userTrackingMode) { diff --git a/platform/ios/app/Storyboard.storyboard b/platform/ios/app/Storyboard.storyboard new file mode 100644 index 000000000..68ee45b8d --- /dev/null +++ b/platform/ios/app/Storyboard.storyboard @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/ios/app/app-info.plist b/platform/ios/app/app-info.plist index eb2080dd0..13452c942 100644 --- a/platform/ios/app/app-info.plist +++ b/platform/ios/app/app-info.plist @@ -45,6 +45,8 @@ The map will display the user's location. UILaunchStoryboardName Default + UIMainStoryboardFile + Storyboard UIRequiredDeviceCapabilities armv7 diff --git a/platform/ios/app/mapboxgl-app.gypi b/platform/ios/app/mapboxgl-app.gypi index 5f9a11873..21941e309 100644 --- a/platform/ios/app/mapboxgl-app.gypi +++ b/platform/ios/app/mapboxgl-app.gypi @@ -11,6 +11,7 @@ 'mac_bundle': 1, 'mac_bundle_resources': [ '