Skip to content

Commit 16b40a0

Browse files
authored
Merge pull request gskbyte#71 from gskbyte/fix-safearea-issue
Fix transplant constraints if safe area insets are active
2 parents 02bc646 + 43e0a8c commit 16b40a0

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# [1.0.3](https://github.com/gskbyte/GSKStretchyHeaderView/releases/tag/1.0.3)
2+
3+
- [Fix layout guides crash on iOS 11](https://github.com/gskbyte/GSKStretchyHeaderView/pull/71)
4+
15
# [1.0.2](https://github.com/gskbyte/GSKStretchyHeaderView/releases/tag/1.0.2)
26

37
- [Fix device rotation issue](https://github.com/gskbyte/GSKStretchyHeaderView/pull/65)
48
- [Add Xcode 9 support](https://github.com/gskbyte/GSKStretchyHeaderView/pull/64)
59
- [Fix contentInset and view hierarchy issues with iOS 11](https://github.com/gskbyte/GSKStretchyHeaderView/pull/68)
610

7-
811
Thanks [@julienpouget](https://github.com/julienpouget)!
912

1013
# [1.0.1](https://github.com/gskbyte/GSKStretchyHeaderView/releases/tag/1.0.1)

GSKStretchyHeaderView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "GSKStretchyHeaderView"
3-
s.version = "1.0.2"
3+
s.version = "1.0.3"
44
s.summary = "A generic, easy to use stretchy header view for UITableView and UICollectionView"
55
s.description = <<-DESC
66
GSKStretchyHeaderView allows you to add a stretchy header view (like Twitter's or Spotify's) to any existing UITableView and UICollectionView. There is no need inherit from custom view controllers, just create your custom header view and add it to your UITableView or UICollectionView. Creating a custom stretchy header view is as easy as inheriting from the base class or using Interface Builder.

GSKStretchyHeaderView/Classes/UIView+GSKTransplantSubviews.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ - (NSLayoutConstraint *)gsk_copyWithFirstItem:(id)firstItem secondItem:(id)secon
2929

3030
@implementation UIView (GSKTransplantSubviews)
3131

32+
- (BOOL)gsk_isSelfOrLayoutGuide:(id)object {
33+
// We can't transplant constraints to layout guides like safe area insets (introduced in iOS 11)
34+
// So we assume the constraints will be related to the superview
35+
// This may become a problem if the safe area insets are not zero, but for header views it's always the case
36+
if (object == self) {
37+
return true;
38+
} else if (@available(iOS 9.0, *)) {
39+
return [object isKindOfClass:[UILayoutGuide class]];
40+
}
41+
return false;
42+
}
43+
3244
- (void)gsk_transplantSubviewsToView:(UIView *)newSuperview {
3345
NSArray<UIView *> *oldSubviews = self.subviews;
3446
NSArray<NSLayoutConstraint *> *oldConstraints = self.constraints;
@@ -47,8 +59,8 @@ - (void)gsk_transplantSubviewsToView:(UIView *)newSuperview {
4759

4860
[self removeConstraints:oldConstraints];
4961
[oldConstraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *oldConstraint, NSUInteger index, BOOL *stop) {
50-
id firstItem = oldConstraint.firstItem == self ? newSuperview : oldConstraint.firstItem;
51-
id secondItem = oldConstraint.secondItem == self ? newSuperview : oldConstraint.secondItem;
62+
id firstItem = [self gsk_isSelfOrLayoutGuide:oldConstraint.firstItem] ? newSuperview : oldConstraint.firstItem;
63+
id secondItem = [self gsk_isSelfOrLayoutGuide:oldConstraint.secondItem] ? newSuperview : oldConstraint.secondItem;
5264
NSLayoutConstraint *constraint = [oldConstraint gsk_copyWithFirstItem:firstItem
5365
secondItem:secondItem];
5466
if ([constraint respondsToSelector:@selector(setActive:)]) {

0 commit comments

Comments
 (0)