[ios] Converted iosapp to use storyboard

This commit is contained in:
Minh Nguyễn
2016-03-03 16:33:25 -08:00
committed by Minh Nguyễn
parent 3879bc6a4e
commit a65730803e
5 changed files with 136 additions and 80 deletions

View File

@@ -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;
}

View File

@@ -19,7 +19,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate>
@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) {

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10109" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="PSe-Ot-7Ff">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10083"/>
</dependencies>
<scenes>
<!--Map View Controller-->
<scene sceneID="p0T-1N-kQ6">
<objects>
<viewController id="WaX-pd-UZQ" userLabel="Map View Controller" customClass="MBXViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="f0q-9O-L15"/>
<viewControllerLayoutGuide type="bottom" id="m8o-i7-QIy"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Z9X-fc-PUC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kNe-zV-9ha" customClass="MGLMapView">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<connections>
<outlet property="delegate" destination="WaX-pd-UZQ" id="za0-3B-qR6"/>
<outletCollection property="gestureRecognizers" destination="lfd-mn-7en" appends="YES" id="0PH-gH-GRm"/>
</connections>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kNe-zV-9ha" firstAttribute="leading" secondItem="Z9X-fc-PUC" secondAttribute="leading" id="53e-Tz-QxF"/>
<constraint firstItem="kNe-zV-9ha" firstAttribute="bottom" secondItem="m8o-i7-QIy" secondAttribute="top" id="Etp-BC-E1N"/>
<constraint firstAttribute="trailing" secondItem="kNe-zV-9ha" secondAttribute="trailing" id="MGr-8G-VEb"/>
<constraint firstItem="kNe-zV-9ha" firstAttribute="top" secondItem="Z9X-fc-PUC" secondAttribute="top" id="qMm-e9-jxH"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="p8W-eP-el5">
<nil key="title"/>
<barButtonItem key="leftBarButtonItem" image="settings.png" id="Jw8-JP-CaZ">
<connections>
<action selector="showSettings:" destination="WaX-pd-UZQ" id="X2C-Ee-Qvt"/>
</connections>
</barButtonItem>
<button key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="KsN-ny-Hou">
<rect key="frame" x="180" y="7" width="240" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
<state key="normal" title="Streets"/>
<connections>
<action selector="cycleStyles:" destination="WaX-pd-UZQ" eventType="touchUpInside" id="PnY-mb-J6m"/>
</connections>
</button>
<barButtonItem key="rightBarButtonItem" image="TrackingLocationOffMask.png" id="CQ1-GP-M6x">
<connections>
<action selector="locateUser:" destination="WaX-pd-UZQ" id="XgF-DB-z3f"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="mapView" destination="kNe-zV-9ha" id="VNR-WO-1q4"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="AAd-8J-9UU" userLabel="First Responder" sceneMemberID="firstResponder"/>
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.5" id="lfd-mn-7en">
<connections>
<action selector="handleLongPress:" destination="WaX-pd-UZQ" id="dkk-bc-rvl"/>
</connections>
</pongPressGestureRecognizer>
</objects>
<point key="canvasLocation" x="1366" y="350"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="LFg-oU-zTK">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="PSe-Ot-7Ff" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="ONr-CS-J5X">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="WaX-pd-UZQ" kind="relationship" relationship="rootViewController" id="lV0-PD-2Ag"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Lom-R7-kwe" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="554" y="350"/>
</scene>
</scenes>
<resources>
<image name="TrackingLocationOffMask.png" width="23" height="23"/>
<image name="settings.png" width="28" height="28"/>
</resources>
<color key="tintColor" red="0.12156862745098039" green="0.5490196078431373" blue="0.6705882352941176" alpha="1" colorSpace="calibratedRGB"/>
</document>

View File

@@ -45,6 +45,8 @@
<string>The map will display the user's location.</string>
<key>UILaunchStoryboardName</key>
<string>Default</string>
<key>UIMainStoryboardFile</key>
<string>Storyboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>

View File

@@ -11,6 +11,7 @@
'mac_bundle': 1,
'mac_bundle_resources': [
'<!@(find ../platform/ios/app/img -type f)',
'./Storyboard.storyboard',
'./points.geojson',
'./polyline.geojson',
'./threestates.geojson',