summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-04-27 15:52:30 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-04-27 15:52:30 -0700
commit5ffa52cab5556639a327471e1927787af6a18231 (patch)
tree76cdadbc32cc24f44b0c76f7820d2b043ab3c9e1 /platform
parent30efdea552e62651102386d354e5841e97cacdf9 (diff)
downloadqtlocation-mapboxgl-5ffa52cab5556639a327471e1927787af6a18231.tar.gz
Automatically find view controller for layout guides
Find the managing view controller by traversing the responder chain.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLMapView.mm42
1 files changed, 23 insertions, 19 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index b61679a7dd..d90f99e0eb 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -323,8 +323,6 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
[container addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCompassTapGesture:)]];
[self addSubview:container];
- self.viewControllerForLayoutGuides = nil;
-
// setup interaction
//
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
@@ -476,15 +474,22 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
[self setNeedsUpdateConstraints];
}
-- (void)setViewControllerForLayoutGuides:(UIViewController *)viewController
+- (UIViewController *)viewControllerForLayoutGuides
{
- _viewControllerForLayoutGuides = viewController;
-
- [self.compass.superview removeConstraints:self.compass.superview.constraints];
- [self.logoBug removeConstraints:self.logoBug.constraints];
- [self.attributionButton removeConstraints:self.attributionButton.constraints];
-
- [self setNeedsUpdateConstraints];
+ // 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;
}
- (void)updateConstraints
@@ -493,21 +498,20 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
// views so they don't underlap navigation or tool bars. If we don't have a reference, apply
// constraints against ourself to maintain (albeit less ideal) placement of the subviews.
//
- UIView *constraintParentView = (self.viewControllerForLayoutGuides.view ?
- self.viewControllerForLayoutGuides.view :
- self);
+ UIViewController *viewController = self.viewControllerForLayoutGuides;
+ UIView *constraintParentView = (viewController.view ? viewController.view : self);
// compass
//
UIView *compassContainer = self.compass.superview;
- if (self.viewControllerForLayoutGuides)
+ if (viewController)
{
[constraintParentView addConstraint:
[NSLayoutConstraint constraintWithItem:compassContainer
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationGreaterThanOrEqual
- toItem:self.viewControllerForLayoutGuides.topLayoutGuide
+ toItem:viewController.topLayoutGuide
attribute:NSLayoutAttributeBottom
multiplier:1
constant:5]];
@@ -550,10 +554,10 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
// logo bug
//
- if (self.viewControllerForLayoutGuides)
+ if (viewController)
{
[constraintParentView addConstraint:
- [NSLayoutConstraint constraintWithItem:self.viewControllerForLayoutGuides.bottomLayoutGuide
+ [NSLayoutConstraint constraintWithItem:viewController.bottomLayoutGuide
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.logoBug
@@ -581,10 +585,10 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
// attribution button
//
- if (self.viewControllerForLayoutGuides)
+ if (viewController)
{
[constraintParentView addConstraint:
- [NSLayoutConstraint constraintWithItem:self.viewControllerForLayoutGuides.bottomLayoutGuide
+ [NSLayoutConstraint constraintWithItem:viewController.bottomLayoutGuide
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.attributionButton