Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 36e5ea38b6 | |||
| c6fcfa1d2a | |||
| 70e603a058 | |||
| e488b4c76b | |||
| f1d9606940 | |||
| 93750ca9a2 | |||
| 34c81e7e93 | |||
| 9a9dfa63f1 | |||
| d01eb06cfb | |||
| 9e4e2c7ccb | |||
| bbe0a06a1e | |||
| ff693f7381 | |||
| 4c1e52ca88 |
@@ -16,10 +16,12 @@
|
||||
@property (weak, nonatomic) IBOutlet UITextField *txtNotificationMessage;
|
||||
@property (weak, nonatomic) IBOutlet UISegmentedControl *segFromStyle;
|
||||
@property (weak, nonatomic) IBOutlet UISegmentedControl *segToStyle;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *notificationStyleLabel;
|
||||
|
||||
@property (strong, nonatomic) CWStatusBarNotification *notification;
|
||||
|
||||
- (IBAction)sliderDurationChanged:(UISlider *)sender;
|
||||
- (IBAction)notificationStyleChanged:(UISwitch *)sender;
|
||||
- (IBAction)btnShowNotificationPressed:(UIButton *)sender;
|
||||
- (IBAction)btnShowCustomNotificationPressed:(UIButton *)sender;
|
||||
|
||||
|
||||
@@ -60,6 +60,12 @@
|
||||
[self updateDurationLabel];
|
||||
}
|
||||
|
||||
- (IBAction)notificationStyleChanged:(UISwitch *)sender
|
||||
{
|
||||
self.notificationStyleLabel.text = sender.on ? @"Status Bar" : @"Navigation Bar";
|
||||
self.notification.notificationStyle = sender.on ? CWNotificationStyleStatusBarNotification : CWNotificationStyleNavigationBarNotification;
|
||||
}
|
||||
|
||||
# pragma mark - show notification
|
||||
|
||||
- (IBAction)btnShowNotificationPressed:(UIButton *)sender
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MainViewController">
|
||||
<connections>
|
||||
<outlet property="lblDuration" destination="oAK-DR-B27" id="roa-nx-2td"/>
|
||||
<outlet property="notificationStyleLabel" destination="vCP-z3-d8I" id="w8D-aD-anT"/>
|
||||
<outlet property="segFromStyle" destination="vWx-wx-d32" id="Zvu-PE-8D7"/>
|
||||
<outlet property="segToStyle" destination="Bza-7R-910" id="CkD-Lr-RCl"/>
|
||||
<outlet property="sliderDuration" destination="lnj-T4-sfz" id="BYx-MN-Cnz"/>
|
||||
@@ -82,6 +83,32 @@
|
||||
<action selector="btnShowNotificationPressed:" destination="-1" eventType="touchUpInside" id="jNW-Ie-NPn"/>
|
||||
</connections>
|
||||
</button>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jdx-ge-BUc">
|
||||
<rect key="frame" x="110" y="332" width="195" height="45"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Status Bar" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vCP-z3-d8I">
|
||||
<rect key="frame" x="2" y="12" width="81" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kMg-IK-wId">
|
||||
<rect key="frame" x="129" y="7" width="51" height="31"/>
|
||||
<connections>
|
||||
<action selector="notificationStyleChanged:" destination="-1" eventType="valueChanged" id="l5q-T2-kkR"/>
|
||||
</connections>
|
||||
</switch>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="vCP-z3-d8I" firstAttribute="centerY" secondItem="kMg-IK-wId" secondAttribute="centerY" id="3SI-Am-gjr"/>
|
||||
<constraint firstItem="vCP-z3-d8I" firstAttribute="leading" secondItem="jdx-ge-BUc" secondAttribute="leading" constant="2" id="JX1-pS-6MA"/>
|
||||
<constraint firstAttribute="width" constant="195" id="ULf-xN-mdP"/>
|
||||
<constraint firstAttribute="trailing" secondItem="kMg-IK-wId" secondAttribute="trailing" constant="17" id="UMt-vg-87u"/>
|
||||
<constraint firstAttribute="centerY" secondItem="vCP-z3-d8I" secondAttribute="centerY" id="VC6-YO-6GP"/>
|
||||
<constraint firstAttribute="height" constant="45" id="x6g-OL-a8r"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
@@ -89,9 +116,11 @@
|
||||
<constraint firstItem="lnj-T4-sfz" firstAttribute="leading" secondItem="nHX-St-Osi" secondAttribute="leading" id="7da-li-6Kn"/>
|
||||
<constraint firstItem="vWx-wx-d32" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" id="8hY-Bj-MI2"/>
|
||||
<constraint firstItem="oAK-DR-B27" firstAttribute="leading" secondItem="nHX-St-Osi" secondAttribute="trailing" constant="8" symbolic="YES" id="9ki-g4-vZj"/>
|
||||
<constraint firstItem="jdx-ge-BUc" firstAttribute="centerX" secondItem="E8G-aN-rjr" secondAttribute="centerX" id="CSN-1b-hyf"/>
|
||||
<constraint firstItem="oAK-DR-B27" firstAttribute="trailing" secondItem="lnj-T4-sfz" secondAttribute="trailing" id="DF9-5s-ORR"/>
|
||||
<constraint firstItem="nHX-St-Osi" firstAttribute="firstBaseline" secondItem="oAK-DR-B27" secondAttribute="firstBaseline" id="ELp-HE-4nH"/>
|
||||
<constraint firstItem="VqG-wR-oYI" firstAttribute="top" secondItem="nHX-St-Osi" secondAttribute="bottom" constant="7" id="I7c-GM-lko"/>
|
||||
<constraint firstItem="jdx-ge-BUc" firstAttribute="top" secondItem="E8G-aN-rjr" secondAttribute="bottom" constant="5" id="PQJ-pr-K5R"/>
|
||||
<constraint firstItem="vWx-wx-d32" firstAttribute="top" secondItem="1" secondAttribute="top" constant="78" id="UEb-Dv-gVI"/>
|
||||
<constraint firstItem="DId-6z-9ak" firstAttribute="centerX" secondItem="VqG-wR-oYI" secondAttribute="centerX" id="UR8-ES-cIh"/>
|
||||
<constraint firstItem="DId-6z-9ak" firstAttribute="top" secondItem="VqG-wR-oYI" secondAttribute="bottom" constant="10" id="ZgW-j6-ji5"/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "CWStatusBarNotification"
|
||||
s.version = "2.2.0"
|
||||
s.version = "2.2.2"
|
||||
s.summary = "A library that creates status bar notifications."
|
||||
s.description = "CWStatusBarNotification is a library allows you to present a beautiful text-based notification in the status bar."
|
||||
s.homepage = "https://github.com/cezarywojcik/CWStatusBarNotification"
|
||||
|
||||
@@ -15,6 +15,9 @@ typedef void(^CWCompletionBlock)(void);
|
||||
@end
|
||||
|
||||
@interface CWWindowContainer : UIWindow
|
||||
|
||||
@property (assign, nonatomic) CGFloat notificationHeight;
|
||||
|
||||
@end
|
||||
|
||||
@interface CWStatusBarNotification : NSObject
|
||||
@@ -61,5 +64,6 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
|
||||
- (void)displayNotificationWithView:(UIView *)view forDuration:(CGFloat)duration;
|
||||
- (void)displayNotificationWithView:(UIView *)view completion:(void (^)(void))completion;
|
||||
- (void)dismissNotification;
|
||||
- (void)dismissNotificationWithCompletion:(void(^)(void))completion;
|
||||
|
||||
@end
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
height = [UIApplication sharedApplication].statusBarFrame.size.height;
|
||||
}
|
||||
|
||||
if (point.y > 0 && point.y < height) {
|
||||
if (point.y > 0 && point.y < (self.notificationHeight != 0.0 ? self.notificationHeight : height)) {
|
||||
return [super hitTest:point withEvent:event];
|
||||
}
|
||||
|
||||
@@ -267,11 +267,8 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
|
||||
- (void)updateStatusBarFrame
|
||||
{
|
||||
if (self.isCustomView) {
|
||||
self.customView.frame = [self getNotificationLabelFrame];
|
||||
} else {
|
||||
self.notificationLabel.frame = [self getNotificationLabelFrame];
|
||||
}
|
||||
UIView *view = self.isCustomView ? self.customView : self.notificationLabel;
|
||||
view.frame = [self getNotificationLabelFrame];
|
||||
self.statusBarView.hidden = YES;
|
||||
}
|
||||
|
||||
@@ -320,7 +317,18 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
|
||||
- (void)createNotificationCustomView:(UIView *)view
|
||||
{
|
||||
self.customView = view;
|
||||
self.customView = [[UIView alloc] init];
|
||||
// Doesn't use autoresizing masks so that we can create constraints below manually
|
||||
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
[self.customView addSubview:view];
|
||||
|
||||
// Setup Auto Layout constaints so that the custom view that is added is constained to be the same
|
||||
// size as its superview, whose frame will be altered
|
||||
[self.customView addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.customView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0]];
|
||||
[self.customView addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.customView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]];
|
||||
[self.customView addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.customView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]];
|
||||
[self.customView addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.customView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]];
|
||||
|
||||
[self setupNotificationView:self.customView];
|
||||
}
|
||||
|
||||
@@ -332,6 +340,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
self.notificationWindow.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.notificationWindow.windowLevel = UIWindowLevelStatusBar;
|
||||
self.notificationWindow.rootViewController = [UIViewController new];
|
||||
self.notificationWindow.notificationHeight = [self getNotificationLabelHeight];
|
||||
}
|
||||
|
||||
- (void)createStatusBarView
|
||||
@@ -463,10 +472,11 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
|
||||
// create status bar view
|
||||
[self createStatusBarView];
|
||||
|
||||
|
||||
// add view to window
|
||||
[self.notificationWindow.rootViewController.view addSubview:self.customView];
|
||||
[self.notificationWindow.rootViewController.view bringSubviewToFront:self.customView];
|
||||
UIView *rootView = self.notificationWindow.rootViewController.view;
|
||||
[rootView addSubview:self.customView];
|
||||
[rootView bringSubviewToFront:self.customView];
|
||||
[self.notificationWindow setHidden:NO];
|
||||
|
||||
// checking for screen orientation change
|
||||
@@ -485,6 +495,11 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
}
|
||||
|
||||
- (void)dismissNotification
|
||||
{
|
||||
[self dismissNotificationWithCompletion:nil];
|
||||
}
|
||||
|
||||
- (void)dismissNotificationWithCompletion:(void (^)(void))completion
|
||||
{
|
||||
if (self.notificationIsShowing) {
|
||||
cancel_delayed_block(self.dismissHandle);
|
||||
@@ -503,7 +518,14 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
self.notificationIsDismissing = NO;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
|
||||
if (completion) {
|
||||
completion();
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
if (completion) {
|
||||
completion();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Works for iPhone and iPad.
|
||||
|
||||
### CocoaPods
|
||||
|
||||
`pod 'CWStatusBarNotification', '~> 2.2.0'`
|
||||
`pod 'CWStatusBarNotification', '~> 2.2.2'`
|
||||
|
||||
### Manual
|
||||
|
||||
@@ -124,7 +124,7 @@ As of version `2.2.0`, you can choose to present a custom view in lieu of presen
|
||||
|
||||
```objc
|
||||
UIView *view = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil][0];
|
||||
[self.notification displayNotificationWithView:view forDuration:self.sliderDuration.value];
|
||||
[self.notification displayNotificationWithView:view forDuration:self.sliderDuration.value];
|
||||
```
|
||||
|
||||
You can also display the notification and choose when to dismiss it as usual:
|
||||
|
||||
Reference in New Issue
Block a user