summaryrefslogtreecommitdiff
path: root/platform/ios/src/UIView+MGLAdditions.m
diff options
context:
space:
mode:
authorLloyd Sheng <i@lloydsheng.com>2019-03-11 23:06:16 +0800
committerGitHub <noreply@github.com>2019-03-11 23:06:16 +0800
commit60ceac5efc3d77199f773f08400fe1d53d5a1b90 (patch)
tree782c821978c8d4b7da2aff2aef9ab24b3c70e88e /platform/ios/src/UIView+MGLAdditions.m
parent5ccc5b7c360827fe58698c28cae4df399310e4d1 (diff)
downloadqtlocation-mapboxgl-60ceac5efc3d77199f773f08400fe1d53d5a1b90.tar.gz
[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
Diffstat (limited to 'platform/ios/src/UIView+MGLAdditions.m')
-rw-r--r--platform/ios/src/UIView+MGLAdditions.m69
1 files changed, 69 insertions, 0 deletions
diff --git a/platform/ios/src/UIView+MGLAdditions.m b/platform/ios/src/UIView+MGLAdditions.m
new file mode 100644
index 0000000000..43c54409bd
--- /dev/null
+++ b/platform/ios/src/UIView+MGLAdditions.m
@@ -0,0 +1,69 @@
+#import "UIView+MGLAdditions.h"
+
+@implementation UIView (MGLAdditions)
+
+- (UIViewController *)mgl_viewControllerForLayoutGuides
+{
+ // Per -[UIResponder nextResponder] documentation, a UIView’s next responder
+ // is its managing UIViewController if applicable, or otherwise its
+ // superview. UIWindow’s next responder is UIApplication, which has no next
+ // responder.
+ UIResponder *laterResponder = self;
+ while ([laterResponder isKindOfClass:[UIView class]])
+ {
+ laterResponder = laterResponder.nextResponder;
+ }
+ if ([laterResponder isKindOfClass:[UIViewController class]])
+ {
+ return (UIViewController *)laterResponder;
+ }
+ return nil;
+}
+
+- (NSLayoutYAxisAnchor *)mgl_safeTopAnchor {
+ if (@available(iOS 11.0, *)) {
+ return self.safeAreaLayoutGuide.topAnchor;
+ } else {
+ UIViewController *viewController = self.mgl_viewControllerForLayoutGuides;
+ BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets;
+ if (useLayoutGuides) {
+ return viewController.topLayoutGuide.bottomAnchor;
+ }
+ else {
+ return self.topAnchor;
+ }
+ }
+}
+
+- (NSLayoutXAxisAnchor *)mgl_safeLeadingAnchor {
+ if (@available(iOS 11.0, *)) {
+ return self.safeAreaLayoutGuide.leadingAnchor;
+ } else {
+ return self.leadingAnchor;
+ }
+}
+
+- (NSLayoutYAxisAnchor *)mgl_safeBottomAnchor {
+ if (@available(iOS 11.0, *)) {
+ return self.safeAreaLayoutGuide.bottomAnchor;
+ } else {
+ UIViewController *viewController = self.mgl_viewControllerForLayoutGuides;
+ BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets;
+ if (useLayoutGuides) {
+ return viewController.bottomLayoutGuide.topAnchor;
+ }
+ else {
+ return self.bottomAnchor;
+ }
+ }
+}
+
+- (NSLayoutXAxisAnchor *)mgl_safeTrailingAnchor {
+ if (@available(iOS 11.0, *)) {
+ return self.safeAreaLayoutGuide.trailingAnchor;
+ } else {
+ return self.trailingAnchor;
+ }
+}
+
+@end