This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Enable developers to change position of ornaments (#13911)
* APIs for change position of ornaments * Use anchors APIs and emove iOS8 layout code * Add ornaments layout tests
- Loading branch information
1 parent
5ccc5b7
commit 60ceac5
Showing
13 changed files
with
558 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface MBXOrnamentsViewController : UIViewController | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#import "MBXOrnamentsViewController.h" | ||
|
||
@import Mapbox; | ||
|
||
@interface MBXOrnamentsViewController ()<MGLMapViewDelegate> | ||
|
||
@property (nonatomic) MGLMapView *mapView; | ||
@property (nonatomic) NSTimer *timer; | ||
@property (nonatomic) NSInteger currentPositionIndex; | ||
|
||
@end | ||
|
||
@implementation MBXOrnamentsViewController | ||
|
||
- (void)setCurrentPositionIndex:(NSInteger)currentPositionIndex { | ||
MGLOrnamentPosition ornamentPositions[5][4] = { | ||
{ | ||
MGLOrnamentPositionTopLeft, | ||
MGLOrnamentPositionTopRight, | ||
MGLOrnamentPositionBottomRight, | ||
MGLOrnamentPositionBottomLeft | ||
}, | ||
{ | ||
MGLOrnamentPositionTopRight, | ||
MGLOrnamentPositionBottomRight, | ||
MGLOrnamentPositionBottomLeft, | ||
MGLOrnamentPositionTopLeft | ||
}, | ||
{ | ||
MGLOrnamentPositionBottomRight, | ||
MGLOrnamentPositionBottomLeft, | ||
MGLOrnamentPositionTopLeft, | ||
MGLOrnamentPositionTopRight | ||
}, | ||
{ | ||
MGLOrnamentPositionBottomLeft, | ||
MGLOrnamentPositionTopLeft, | ||
MGLOrnamentPositionTopRight, | ||
MGLOrnamentPositionBottomRight | ||
}, | ||
{ | ||
MGLOrnamentPositionTopLeft, | ||
MGLOrnamentPositionTopRight, | ||
MGLOrnamentPositionBottomRight, | ||
MGLOrnamentPositionBottomLeft | ||
} | ||
}; | ||
MGLOrnamentPosition *currentPosition = ornamentPositions[currentPositionIndex]; | ||
self.mapView.scaleBarPosition = currentPosition[0]; | ||
self.mapView.compassViewPosition = currentPosition[1]; | ||
self.mapView.logoViewPosition = currentPosition[2]; | ||
self.mapView.attributionButtonPosition = currentPosition[3]; | ||
|
||
_currentPositionIndex = currentPositionIndex; | ||
} | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.title = @"Ornaments"; | ||
|
||
MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds]; | ||
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | ||
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(39.915143, 116.404053) | ||
zoomLevel:16 | ||
direction:30 | ||
animated:NO]; | ||
mapView.delegate = self; | ||
mapView.showsScale = YES; | ||
[self.view addSubview:mapView]; | ||
|
||
self.mapView = mapView; | ||
} | ||
|
||
- (void)viewDidDisappear:(BOOL)animated { | ||
[self.timer invalidate]; | ||
self.timer = nil; | ||
} | ||
|
||
- (void)viewDidAppear:(BOOL)animated { | ||
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 | ||
target:self | ||
selector:@selector(onTimerTick) | ||
userInfo:nil | ||
repeats:YES]; | ||
} | ||
|
||
- (void)onTimerTick { | ||
self.currentPositionIndex ++; | ||
if (self.currentPositionIndex >= 4) { | ||
self.currentPositionIndex = 0; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.