[ios] simplified constraints and fixed regression 6954 (#7084)

* [ios] simplified constraints and fixed regression 6954

* [ios] removed excessive constraints

* [ios] removed compass container view
This commit is contained in:
Fredrik Karlsson
2016-11-20 13:16:20 +01:00
committed by GitHub
parent e858dba86d
commit 307f8e4f41

View File

@@ -468,10 +468,8 @@ public:
_compassView.accessibilityTraits = UIAccessibilityTraitButton;
_compassView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_LABEL", nil, nil, @"Compass", @"Accessibility label");
_compassView.accessibilityHint = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_HINT", nil, nil, @"Rotates the map to face due north", @"Accessibility hint");
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
[container addSubview:_compassView];
container.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:container];
_compassView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_compassView];
_compassViewConstraints = [NSMutableArray array];
// setup interaction
@@ -763,26 +761,16 @@ public:
- (void)updateConstraints
{
// If we have a view controller reference and its automaticallyAdjustsScrollViewInsets
// is set to YES, use its view as the parent for constraints. -[MGLMapView adjustContentInset]
// already take top and bottom layout guides into account. If we don't have a reference, apply
// constraints against ourself to maintain placement of the subviews.
//
UIViewController *viewController = self.viewControllerForLayoutGuides;
BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets;
UIView *view = useLayoutGuides ? viewController.view : self;
// compass
//
UIView *compassContainer = self.compassView.superview;
[view removeConstraints:self.compassViewConstraints];
[self removeConstraints:self.compassViewConstraints];
[self.compassViewConstraints removeAllObjects];
[self.compassViewConstraints addObject:
[NSLayoutConstraint constraintWithItem:compassContainer
[NSLayoutConstraint constraintWithItem:self.compassView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:view
toItem:self
attribute:NSLayoutAttributeTop
multiplier:1
constant:5 + self.contentInset.top]];
@@ -791,34 +779,16 @@ public:
[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:compassContainer
toItem:self.compassView
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:5 + self.contentInset.right]];
UIImage *compassImage = self.compassView.image;
[self.compassViewConstraints addObject:
[NSLayoutConstraint constraintWithItem:compassContainer
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:compassImage.size.width]];
[self.compassViewConstraints addObject:
[NSLayoutConstraint constraintWithItem:compassContainer
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:compassImage.size.height]];
[view addConstraints:self.compassViewConstraints];
[self addConstraints:self.compassViewConstraints];
// logo bug
//
[view removeConstraints:self.logoViewConstraints];
[self removeConstraints:self.logoViewConstraints];
[self.logoViewConstraints removeAllObjects];
[self.logoViewConstraints addObject:
@@ -838,11 +808,11 @@ public:
attribute:NSLayoutAttributeLeading
multiplier:1
constant:8 + self.contentInset.left]];
[view addConstraints:self.logoViewConstraints];
[self addConstraints:self.logoViewConstraints];
// attribution button
//
[view removeConstraints:self.attributionButtonConstraints];
[self removeConstraints:self.attributionButtonConstraints];
[self.attributionButtonConstraints removeAllObjects];
[self.attributionButtonConstraints addObject:
@@ -862,7 +832,7 @@ public:
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:8 + self.contentInset.right]];
[view addConstraints:self.attributionButtonConstraints];
[self addConstraints:self.attributionButtonConstraints];
[super updateConstraints];
}