Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Added Swift 3 Examples #35

Merged
merged 17 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Mapbox.framework
Examples.xcodeproj/project.xcworkspace/

.DS_Store
xcuserdata/
DerivedData/
514 changes: 412 additions & 102 deletions Examples.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Examples/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@


@end

1 change: 0 additions & 1 deletion Examples/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Expand Down
20 changes: 20 additions & 0 deletions Examples/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
Expand Down Expand Up @@ -52,6 +62,16 @@
"filename" : "Icon-60@3x.png",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
Expand Down
47 changes: 24 additions & 23 deletions Examples/Examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,37 @@
@implementation Examples

+ (NSArray *)list {

NSArray *initialList = [[NSMutableArray alloc] initWithArray:@[
MBXExampleAnnotationView,
MBXExampleCalloutDelegateUsage,
MBXExampleCameraAnimation,
MBXExampleCustomAnnotationModel,
MBXExampleCustomCalloutView,
MBXExampleCustomRasterStyle,
MBXExampleCustomStyle,
MBXExampleDefaultStyles,
MBXExampleDraggableAnnotationView,
MBXExampleDrawingAGeoJSONLine,
MBXExampleDrawingACustomMarker,
MBXExampleDrawingAMarker,
MBXExampleDrawingAPolygon,
MBXExampleOfflinePack,
MBXExamplePointConversion,
MBXExampleSatelliteStyle,
MBXExampleSimpleMapView,
MBXExampleUserTrackingModes,
]];

MBXExampleAnnotationView,
MBXExampleCalloutDelegateUsage,
MBXExampleCameraAnimation,
MBXExampleCustomAnnotationModel,
MBXExampleCustomCalloutView,
MBXExampleCustomRasterStyle,
MBXExampleCustomStyle,
MBXExampleDefaultStyles,
MBXExampleDraggableAnnotationView,
MBXExampleDrawingAGeoJSONLine,
MBXExampleDrawingACustomMarker,
MBXExampleDrawingAMarker,
MBXExampleDrawingAPolygon,
MBXExampleOfflinePack,
MBXExamplePointConversion,
MBXExampleSatelliteStyle,
MBXExampleSimpleMapView,
MBXExampleUserTrackingModes,
]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s manually go back to the shorter indentation.

NSMutableArray *meh = [[NSMutableArray alloc] init];

[initialList enumerateObjectsUsingBlock:^(NSString *objcName, NSUInteger index, BOOL *stop) {
NSString *swiftName = [NSString stringWithFormat:@"%@_Swift", objcName];

[meh insertObject:swiftName atIndex:index*2];
[meh insertObject:objcName atIndex:index*2];
}];

return [meh copy];
}

Expand Down
1 change: 0 additions & 1 deletion Examples/ExamplesContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@interface ExamplesContainerViewController ()

@end

@implementation ExamplesContainerViewController

- (void)viewDidLoad {
Expand Down
1 change: 0 additions & 1 deletion Examples/ExamplesTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ @interface ExamplesTableViewController ()
@property (nonatomic) NSArray *examples;

@end

@implementation ExamplesTableViewController

- (void)viewDidLoad {
Expand Down
27 changes: 14 additions & 13 deletions Examples/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10112" systemVersion="15E39d" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="icM-J6-7Ve">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="icM-J6-7Ve">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10083"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Mapbox Examples Table-->
<scene sceneID="Z8w-ct-53h">
<objects>
<tableViewController title="Mapbox Examples Table" id="rYw-fr-DVv" customClass="ExamplesTableViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="jqC-bf-Q1D">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="ExampleCell" textLabel="2OV-ag-M78" style="IBUITableViewCellStyleDefault" id="uOq-7b-YXm">
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
<rect key="frame" x="0.0" y="92" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="uOq-7b-YXm" id="Y0e-IA-9M7">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<frame key="frameInset" width="375" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2OV-ag-M78">
<rect key="frame" x="15" y="0.0" width="570" height="43.5"/>
<frame key="frameInset" minX="15" width="345" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down Expand Up @@ -55,17 +56,17 @@
<viewControllerLayoutGuide type="bottom" id="Gia-78-0rw"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="ySG-gy-6RJ">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aWc-it-OfW">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<containerView opaque="NO" contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aWc-it-OfW">
<frame key="frameInset" width="600" height="600"/>
<connections>
<segue destination="198-d0-SS2" kind="embed" id="RV5-UC-Iwr"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="aWc-it-OfW" firstAttribute="top" secondItem="ySG-gy-6RJ" secondAttribute="top" id="CUW-TL-Tdy"/>
<constraint firstItem="aWc-it-OfW" firstAttribute="leading" secondItem="ySG-gy-6RJ" secondAttribute="leading" id="Rvt-2P-AM6"/>
Expand Down Expand Up @@ -105,7 +106,7 @@
<view key="view" contentMode="scaleToFill" id="23Q-aT-BkF">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Eur-mY-Rlz" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
3 changes: 0 additions & 3 deletions Examples/ObjectiveC/AnnotationViewExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// MGLAnnotationView subclass
@interface CustomAnnotationView : MGLAnnotationView
@end

@implementation CustomAnnotationView

- (void)layoutSubviews {
Expand All @@ -41,12 +40,10 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
}

@end

//
// Example view controller
@interface AnnotationViewExample () <MGLMapViewDelegate>
@end

@implementation AnnotationViewExample

- (void)viewDidLoad {
Expand Down
107 changes: 107 additions & 0 deletions Examples/ObjectiveC/AnnotationViewExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// AnnotationViewExample.swift
// Examples
//
// Created by Jason Wray on 6/23/16.
// Copyright © 2016 Mapbox. All rights reserved.
//
#if swift(>=3.0)
import Mapbox

@objc(AnnotationViewExample_Swift)

// Example view controller
class AnnotationViewExample_Swift: UIViewController, MGLMapViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

exampleType = .Annotation
print(exampleType)
let mapView = MGLMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.styleURL = MGLStyle.darkStyleURL(withVersion: 9)
mapView.tintColor = .lightGray
mapView.centerCoordinate = CLLocationCoordinate2DMake(0, 66)
mapView.zoomLevel = 2
mapView.delegate = self
view.addSubview(mapView)

// Specify coordinates for our annotations.
let coordinates = [
CLLocationCoordinate2DMake(0, 33),
CLLocationCoordinate2DMake(0, 66),
CLLocationCoordinate2DMake(0, 99),
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: align the indentation of the closing bracket with let.


// Fill an array with point annotations and add it to the map.
var pointAnnotations = [MGLPointAnnotation]()
for coordinate in coordinates {
let point = MGLPointAnnotation()
point.coordinate = coordinate
point.title = "\(coordinate.latitude), \(coordinate.longitude)"
pointAnnotations.append(point)
}

mapView.addAnnotations(pointAnnotations)
}

// MARK: - MGLMapViewDelegate methods

// This delegate method is where you tell the map to load a view for a specific annotation. To load a static MGLAnnotationImage, you would use `-mapView:imageForAnnotation:`.
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
// This example is only concerned with point annotations.
guard annotation is MGLPointAnnotation else {
return nil
}

// Use the point annotation’s longitude value (as a string) as the reuse identifier for its view.
let reuseIdentifier = "\(annotation.coordinate.longitude)"

// For better performance, always try to reuse existing annotations.
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)

// If there’s no reusable annotation view available, initialize a new one.
if annotationView == nil {
annotationView = CustomAnnotationView(reuseIdentifier: reuseIdentifier)
annotationView!.frame = CGRect(x: 0, y: 0, width: 40, height: 40)

// Set the annotation view’s background color to a value determined by its longitude.
let hue = CGFloat(annotation.coordinate.longitude) / 100
annotationView!.backgroundColor = UIColor(hue: hue, saturation: 0.5, brightness: 1, alpha: 1)
}

return annotationView
}

func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
}

//
// MGLAnnotationView subclass
class CustomAnnotationView: MGLAnnotationView {
override func layoutSubviews() {
super.layoutSubviews()

// Force the annotation view to maintain a constant size when the map is tilted.
scalesWithViewingDistance = false

// Use CALayer’s corner radius to turn this view into a circle.
layer.cornerRadius = frame.width / 2
layer.borderWidth = 2
layer.borderColor = UIColor.white.cgColor
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Animate the border width in/out, creating an iris effect.
let animation = CABasicAnimation(keyPath: "borderWidth")
animation.duration = 0.1
layer.borderWidth = selected ? frame.width / 4 : 2
layer.add(animation, forKey: "borderWidth")
}
}
#endif
1 change: 0 additions & 1 deletion Examples/ObjectiveC/CalloutDelegateUsageExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ @interface CalloutDelegateUsageExample () <MGLMapViewDelegate>
@property MGLMapView *mapView;

@end

@implementation CalloutDelegateUsageExample

- (void)viewDidLoad
Expand Down
Loading