Skip to content

Commit 58bd395

Browse files
committed
Net Fix.
1 parent 37c9091 commit 58bd395

File tree

6 files changed

+80
-27
lines changed

6 files changed

+80
-27
lines changed

CSNotificationView/CSColorView.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// CSColorView.h
3+
// CSNotificationViewDemo
4+
//
5+
// Created by Remigiusz Herba on 15/10/15.
6+
//
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "CSNotificationView_Private.h"
11+
12+
@interface CSColorView : UIView <CSNotificationViewBlurViewProtocol>
13+
14+
@end

CSNotificationView/CSColorView.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// CSColorView.m
3+
// CSNotificationViewDemo
4+
//
5+
// Created by Remigiusz Herba on 15/10/15.
6+
//
7+
//
8+
9+
#import "CSColorView.h"
10+
11+
@implementation CSColorView
12+
13+
- (void)setBlurTintColor:(UIColor *)tintColor
14+
{
15+
self.backgroundColor = tintColor;
16+
}
17+
18+
@end

CSNotificationView/CSNotificationView.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ typedef void(^CSVoidBlock)();
6464
* the parent view controller's view for presentation.
6565
* @param viewController The view controller in which the notification shall be presented.
6666
*/
67-
- (instancetype)initWithParentViewController:(UIViewController*)viewController NS_DESIGNATED_INITIALIZER;
67+
- (instancetype)initWithParentViewController:(UIViewController*)viewController;
68+
69+
/**
70+
* Why initialize with the view controller?
71+
* CSNotificationView stays visible if `viewController` is pushed off the UINavigationController stack.
72+
* Furthermore, presentation in a UITableViewController is not possible so CSNotificationView uses
73+
* the parent view controller's view for presentation.
74+
* @param viewController The view controller in which the notification shall be presented.
75+
*/
76+
- (instancetype)initWithParentViewControllerWithoutBlur:(UIViewController*)viewController;
6877

6978
#pragma mark - presentation
7079

CSNotificationView/CSNotificationView.m

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#import "CSLayerStealingBlurView.h"
1313
#import "CSNativeBlurView.h"
14+
#import "CSColorView.h"
1415

1516
@implementation CSNotificationView
1617

@@ -100,46 +101,38 @@ + (CSNotificationView*)notificationViewWithParentViewController:(UIViewControlle
100101

101102
#pragma mark - lifecycle
102103

103-
- (instancetype)initWithParentViewController:(UIViewController*)viewController
104+
- (instancetype)initWithParentViewController:(UIViewController *)viewController blurView:(UIView<CSNotificationViewBlurViewProtocol> *)blurView
104105
{
105106
self = [super initWithFrame:CGRectZero];
106107
if (self) {
107-
108+
108109
self.backgroundColor = [UIColor clearColor];
109-
110+
110111
//Blur view
111112
{
112-
113-
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
114-
//Use native effects
115-
self.blurView = [[CSNativeBlurView alloc] initWithFrame:CGRectZero];
116-
} else {
117-
//Use layer stealing
118-
self.blurView = [[CSLayerStealingBlurView alloc] initWithFrame:CGRectZero];
119-
}
120-
113+
self.blurView = blurView;
121114
self.blurView.userInteractionEnabled = NO;
122115
self.blurView.translatesAutoresizingMaskIntoConstraints = NO;
123116
self.blurView.clipsToBounds = NO;
124117
[self insertSubview:self.blurView atIndex:0];
125-
118+
126119
}
127-
120+
128121
//Parent view
129122
{
130123
self.parentViewController = viewController;
131-
124+
132125
NSAssert(!([self.parentViewController isKindOfClass:[UITableViewController class]] && !self.parentViewController.navigationController), @"Due to a bug in iOS 7.0.1|2|3 UITableViewController, CSNotificationView cannot present in UITableViewController without a parent UINavigationController");
133-
126+
134127
if (self.parentViewController.navigationController) {
135128
self.parentNavigationController = self.parentViewController.navigationController;
136129
}
137130
if ([self.parentViewController isKindOfClass:[UINavigationController class]]) {
138131
self.parentNavigationController = (UINavigationController*)self.parentViewController;
139132
}
140-
133+
141134
}
142-
135+
143136
//Notifications
144137
{
145138
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(navigationControllerWillShowViewControllerNotification:) name:kCSNotificationViewUINavigationControllerWillShowViewControllerNotification object:nil];
@@ -150,33 +143,33 @@ - (instancetype)initWithParentViewController:(UIViewController*)viewController
150143
{
151144
[self addObserver:self forKeyPath:kCSNavigationBarBoundsKeyPath options:NSKeyValueObservingOptionNew context:kCSNavigationBarObservationContext];
152145
}
153-
146+
154147
//Content views
155148
{
156149
//textLabel
157150
{
158151
_textLabel = [[UILabel alloc] init];
159-
152+
160153
_textLabel.textColor = [UIColor whiteColor];
161154
_textLabel.backgroundColor = [UIColor clearColor];
162155
_textLabel.translatesAutoresizingMaskIntoConstraints = NO;
163-
156+
164157
_textLabel.numberOfLines = 2;
165158
_textLabel.minimumScaleFactor = 0.6;
166159
_textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
167-
160+
168161
UIFontDescriptor* textLabelFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
169162
_textLabel.font = [UIFont fontWithDescriptor:textLabelFontDescriptor size:17.0f];
170163
_textLabel.adjustsFontSizeToFitWidth = YES;
171-
164+
172165
[self addSubview:_textLabel];
173166
}
174167
//symbolView
175168
{
176169
[self updateSymbolView];
177170
}
178171
}
179-
172+
180173
//Interaction
181174
{
182175
//Tap gesture
@@ -185,11 +178,29 @@ - (instancetype)initWithParentViewController:(UIViewController*)viewController
185178
}
186179

187180
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
188-
181+
189182
}
190183
return self;
191184
}
192185

186+
- (instancetype)initWithParentViewControllerWithoutBlur:(UIViewController *)viewController
187+
{
188+
return [self initWithParentViewController:viewController blurView:[[CSColorView alloc] init]];
189+
}
190+
191+
- (instancetype)initWithParentViewController:(UIViewController*)viewController
192+
{
193+
UIView<CSNotificationViewBlurViewProtocol> *blurView;
194+
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
195+
//Use native effects
196+
blurView = [[CSNativeBlurView alloc] initWithFrame:CGRectZero];
197+
} else {
198+
//Use layer stealing
199+
blurView = [[CSLayerStealingBlurView alloc] initWithFrame:CGRectZero];
200+
}
201+
return [self initWithParentViewController:viewController blurView:blurView];
202+
}
203+
193204
- (void)dealloc
194205
{
195206
[[NSNotificationCenter defaultCenter] removeObserver:self];

CSNotificationView/CSNotificationView_Private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static NSString * kCSNavigationBarBoundsKeyPath = @"parentNavigationController.n
1818

1919
@protocol CSNotificationViewBlurViewProtocol <NSObject>
2020

21+
@optional
2122
///The tint of the blur view
2223
- (void)setBlurTintColor:(UIColor*)tintColor;
2324

Example/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ EXTERNAL SOURCES:
1111
SPEC CHECKSUMS:
1212
CSNotificationView: 0792f5220163c2befaf1a9716aa3d5a7d6bd4fb1
1313

14-
COCOAPODS: 0.36.3
14+
COCOAPODS: 0.38.2

0 commit comments

Comments
 (0)