Skip to content

Commit fe923a7

Browse files
committed
When content inset changes (due to a change in the button height due to a change in frame size), notify the subclasses to handle it accordingly.
1 parent 1e2e2e9 commit fe923a7

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

Classes/MTZWhatsNewViewController/MTZWhatsNewGridViewController.m

+10-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ - (void)__MTZWhatsNewGridViewController_Setup
8585
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"whatsnew"];
8686
[self.collectionView registerClass:[MTZWhatsNewFeatureCollectionViewCell class] forCellWithReuseIdentifier:@"feature"];
8787
self.collectionView.backgroundColor = [UIColor clearColor];
88-
self.collectionView.contentInset = self.contentInsets;
89-
self.collectionView.scrollIndicatorInsets = self.contentInsets;
88+
self.collectionView.contentInset = self.contentInset;
89+
self.collectionView.scrollIndicatorInsets = self.contentInset;
9090

9191
// Defaults.
9292
self.templatedIcons = YES;
@@ -95,7 +95,7 @@ - (void)__MTZWhatsNewGridViewController_Setup
9595
- (void)viewDidAppear:(BOOL)animated
9696
{
9797
[super viewDidAppear:animated];
98-
[self.collectionView flashScrollIndicators];
98+
[self.collectionView performSelector:@selector(flashScrollIndicators) withObject:nil afterDelay:0];
9999
}
100100

101101
- (void)styleDidChange
@@ -139,6 +139,13 @@ - (void)setFeatures:(NSDictionary *)features
139139
[self.collectionView reloadData];
140140
}
141141

142+
- (void)contentInsetDidChange
143+
{
144+
[super contentInsetDidChange];
145+
self.collectionView.contentInset = self.contentInset;
146+
self.collectionView.scrollIndicatorInsets = self.contentInset;
147+
}
148+
142149
- (void)setTemplatedIcons:(BOOL)templatedIcons
143150
{
144151
_templatedIcons = templatedIcons;

Classes/MTZWhatsNewViewController/MTZWhatsNewViewController.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ typedef NS_ENUM(NSUInteger, MTZWhatsNewViewControllerStyle) {
7171
/// @discussion This method is called when the style has been changed. You should override this method to perform custom tasks associated with changing the style. If you override this method, you must call super at some point in your implementation. Note that this can be called when the receiver's @c automaticallySetStyle is set to @c YES and not only after changes are made directly to the @c style property.
7272
- (void)styleDidChange __attribute__((objc_requires_super));
7373

74-
/// The content insets to use in a subclss.
75-
@property (nonatomic, readonly) UIEdgeInsets contentInsets;
74+
/// The content inset to use in a subclss.
75+
@property (nonatomic, readonly) UIEdgeInsets contentInset;
76+
77+
/// Notifies the view controller that the content inset has changed.
78+
- (void)contentInsetDidChange __attribute__((objc_requires_super));
7679

7780
@end

Classes/MTZWhatsNewViewController/MTZWhatsNewViewController.m

+42-14
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ @interface MTZWhatsNewViewController ()
1717
/// A private read/write property of `contentView`.
1818
@property (readwrite) UIView *contentView;
1919

20-
/// A private read/write property of `contentInsets`.
21-
@property (readwrite) UIEdgeInsets contentInsets;
20+
/// A private read/write property of `contentInset`.
21+
@property (readwrite) UIEdgeInsets contentInset;
2222

2323
/// The button to dismiss the view controller.
2424
@property (strong, nonatomic) UIButton *dismissButton;
2525

26+
/// The background behind the dismiss button.
27+
@property (strong, nonatomic) UIToolbar *buttonBackground;
28+
2629
@end
2730

2831

@@ -71,10 +74,6 @@ - (void)commonInit
7174
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
7275
self.modalPresentationStyle = UIModalPresentationFormSheet;
7376

74-
CGFloat buttonHeight = [self shouldUseLargeButton] ? 82.0f : 50.0f;
75-
UIFont *buttonFont = [self shouldUseLargeButton] ? [UIFont fontWithName:@"HelveticaNeue-Light" size:29.0f] : [UIFont fontWithName:@"HelveticaNeue" size:18.0f];
76-
self.contentInsets = UIEdgeInsetsMake(0, 0, buttonHeight, 0);
77-
7877
// Background View.
7978
SAMGradientView *gradientView = [[SAMGradientView alloc] init];
8079
self.backgroundView = gradientView;
@@ -91,20 +90,19 @@ - (void)commonInit
9190
[self.view addConstraints:[NSLayoutConstraint constraintsToFillToSuperview:self.contentView]];
9291

9392
// Dismiss Button.
94-
UIToolbar *buttonBackground = [[UIToolbar alloc] init];
95-
[self.view addSubview:buttonBackground];
96-
buttonBackground.translatesAutoresizingMaskIntoConstraints = NO;
97-
[self.view addConstraints:[NSLayoutConstraint constraintsToStickView:buttonBackground toEdges:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]];
98-
[buttonBackground addConstraint:[NSLayoutConstraint constraintToSetStaticHeight:buttonHeight toView:buttonBackground]];
93+
self.buttonBackground = [[UIToolbar alloc] init];
94+
[self.view addSubview:self.buttonBackground];
95+
self.buttonBackground.translatesAutoresizingMaskIntoConstraints = NO;
96+
[self.view addConstraints:[NSLayoutConstraint constraintsToStickView:self.buttonBackground toEdges:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]];
9997

10098
self.dismissButton = [[UIButton alloc] init];
10199
self.dismissButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
102-
[buttonBackground addSubview:self.dismissButton];
100+
[self.buttonBackground addSubview:self.dismissButton];
103101
self.dismissButton.translatesAutoresizingMaskIntoConstraints = NO;
104-
[self.dismissButton.superview addConstraints:[NSLayoutConstraint constraintsToFillToSuperview:self.dismissButton]];
105-
self.dismissButton.titleLabel.font = buttonFont;
106102
[self.dismissButton addTarget:self action:@selector(didTapContinueButton:) forControlEvents:UIControlEventTouchUpInside];
107103

104+
[self reloadButtonHeight];
105+
108106
// Defaults.
109107
self.backgroundGradientTopColor = [UIColor whiteColor];
110108
self.backgroundGradientBottomColor = [UIColor whiteColor];
@@ -113,11 +111,30 @@ - (void)commonInit
113111
self.dismissButtonTitle = NSLocalizedString(@"Get Started", nil);
114112
}
115113

114+
- (void)reloadButtonHeight
115+
{
116+
UIFont *buttonFont = [self shouldUseLargeButton] ? [UIFont fontWithName:@"HelveticaNeue-Light" size:29.0f] : [UIFont fontWithName:@"HelveticaNeue" size:18.0f];
117+
self.dismissButton.titleLabel.font = buttonFont;
118+
119+
CGFloat buttonHeight = [self shouldUseLargeButton] ? 82.0f : 50.0f;
120+
[self.buttonBackground removeConstraints:self.buttonBackground.constraints];
121+
[self.buttonBackground addConstraint:[NSLayoutConstraint constraintToSetStaticHeight:buttonHeight toView:self.buttonBackground]];
122+
[self.buttonBackground addConstraints:[NSLayoutConstraint constraintsToFillToSuperview:self.dismissButton]];
123+
124+
self.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, self.bottomLayoutGuide.length+buttonHeight, 0);
125+
}
126+
116127
- (BOOL)prefersStatusBarHidden
117128
{
118129
return YES;
119130
}
120131

132+
- (void)viewWillLayoutSubviews
133+
{
134+
[super viewWillLayoutSubviews];
135+
[self reloadButtonHeight];
136+
}
137+
121138

122139
#pragma mark - Actions
123140

@@ -172,6 +189,12 @@ - (void)setDismissButtonTitle:(NSString *)dismissButtonText
172189
[self.dismissButton setTitle:_dismissButtonTitle forState:UIControlStateNormal];
173190
}
174191

192+
- (void)setContentInset:(UIEdgeInsets)contentInset
193+
{
194+
_contentInset = contentInset;
195+
[self contentInsetDidChange];
196+
}
197+
175198

176199
#pragma mark - Style
177200

@@ -201,6 +224,11 @@ - (MTZWhatsNewViewControllerStyle)appropriateStyleForBackgroundOfColor:(UIColor
201224
}
202225
}
203226

227+
- (void)contentInsetDidChange
228+
{
229+
// An empty implementation.
230+
}
231+
204232
- (void)styleDidChange
205233
{
206234
// An empty implementation.

0 commit comments

Comments
 (0)