Skip to content

Commit

Permalink
support iPhone X
Browse files Browse the repository at this point in the history
  • Loading branch information
pikacode committed Nov 26, 2017
1 parent beb087c commit ce80ab8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions EBBannerView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Pod::Spec.new do |s|
#

s.name = "EBBannerView"
s.version = "1.0.1"
s.summary = "展示跟iOS9/10/11推送一样的横幅/提示音/振动,或自定义view.Show a banner the same with iOS9/10/11 nofitication(sound/vibrate), or customize."
s.version = "1.0.3"
s.summary = "展示跟iOS9/10/11推送一样的横幅/提示音/振动,或自定义viewShow a banner the same with iOS9/10/11 nofitication(sound/vibrate), or customize."

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand Down
Binary file modified EBBannerView/.DS_Store
Binary file not shown.
49 changes: 36 additions & 13 deletions EBBannerView/Classes/EBBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ @interface EBBannerView(){
@property (nonatomic, assign, readonly)CGFloat calculatedHeight;
@property(nonatomic, assign)EBBannerViewStyle style;

@property (nonatomic, assign, readonly)CGFloat fixedX;
@property (nonatomic, assign, readonly)CGFloat fixedY;
@property (nonatomic, assign, readonly)CGFloat fixedWidth;

@end

@implementation EBBannerView
Expand Down Expand Up @@ -92,11 +96,11 @@ -(void)show{

[sharedWindow.rootViewController.view addSubview:self];

self.frame = CGRectMake(0, -self.standardHeight, ScreenWidth, self.standardHeight);
self.frame = CGRectMake(self.fixedX, -self.standardHeight, self.fixedWidth, self.standardHeight);

WEAK_SELF(weakSelf);
[UIView animateWithDuration:self.animationDuration animations:^{
weakSelf.frame = CGRectMake(0, 0, ScreenWidth, weakSelf.standardHeight);
weakSelf.frame = CGRectMake(weakSelf.fixedX, weakSelf.fixedY, weakSelf.fixedWidth, weakSelf.standardHeight);
} completion:^(BOOL finished) {
_hideTimer = [NSTimer scheduledTimerWithTimeInterval:weakSelf.stayDuration target:weakSelf selector:@selector(hide) userInfo:nil repeats:NO];
}];
Expand All @@ -115,7 +119,7 @@ +(void)showWithContent:(NSString*)content{
-(void)hide{
WEAK_SELF(weakSelf);
[UIView animateWithDuration:self.animationDuration animations:^{
weakSelf.frame = CGRectMake(0, -weakSelf.standardHeight, ScreenWidth, weakSelf.standardHeight);
weakSelf.frame = CGRectMake(weakSelf.fixedX, -weakSelf.standardHeight, weakSelf.fixedWidth, weakSelf.standardHeight);
} completion:^(BOOL finished) {
[weakSelf removeFromSuperview];
}];
Expand All @@ -125,14 +129,7 @@ -(void)applicationDidChangeStatusBarOrientationNotification{
if (!self.superview) {
return;
}
CGSize size = UIScreen.mainScreen.bounds.size;
CGFloat w = MIN(size.width, size.height);
CGFloat h = MAX(size.width, size.height);
if (UIDeviceOrientationIsLandscape(UIDevice.currentDevice.orientation)) {
self.frame = CGRectMake(0, 0, h, self.standardHeight);
}else{
self.frame = CGRectMake(0, 0, w, self.standardHeight);
}
self.frame = CGRectMake(self.fixedX, self.fixedY, self.fixedWidth, self.standardHeight);
}

-(void)addGestureRecognizer{
Expand Down Expand Up @@ -166,9 +163,9 @@ -(void)swipeDownGesture:(UISwipeGestureRecognizer*)gesture{
WEAK_SELF(weakSelf);
CGFloat originHeight = self.contentLabel.frame.size.height;
[UIView animateWithDuration:self.animationDuration animations:^{
weakSelf.frame = CGRectMake(0, 0, ScreenWidth, weakSelf.standardHeight + weakSelf.calculatedHeight - originHeight + 1);
weakSelf.frame = CGRectMake(weakSelf.fixedX, weakSelf.fixedY, weakSelf.fixedWidth, weakSelf.standardHeight + weakSelf.calculatedHeight - originHeight + 1);
} completion:^(BOOL finished) {
weakSelf.frame = CGRectMake(0, 0, ScreenWidth, weakSelf.standardHeight + weakSelf.calculatedHeight - originHeight + 1);
weakSelf.frame = CGRectMake(weakSelf.fixedX, weakSelf.fixedY, weakSelf.fixedWidth, weakSelf.standardHeight + weakSelf.calculatedHeight - originHeight + 1);
}];
}
}
Expand Down Expand Up @@ -251,6 +248,32 @@ -(UInt32)soundID{
return _soundID;
}

-(BOOL)isiPhoneX{
static BOOL isiPhoneX = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CGSize size = UIScreen.mainScreen.bounds.size;
isiPhoneX = MAX(size.width, size.height) == 812;
});
return isiPhoneX;
}

-(CGFloat)fixedX{
return ([self isiPhoneX] && ![self isPortrait]) ? 128 : 0;
}

-(CGFloat)fixedY{
return ([self isiPhoneX] && [self isPortrait]) ? 33 : 0;
}

-(CGFloat)fixedWidth{
return ([self isiPhoneX] && ![self isPortrait]) ? 556 : ScreenWidth;
}

-(BOOL)isPortrait{
return UIDeviceOrientationIsPortrait(UIDevice.currentDevice.orientation);
}

@end


13 changes: 6 additions & 7 deletions EBBannerView/Classes/EBBannerView.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -158,8 +157,8 @@
<rect key="frame" x="0.0" y="36" width="304" height="22"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Content" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PlN-Fu-byf">
<rect key="frame" x="15" y="0.5" width="281" height="20.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
<rect key="frame" x="15" y="2.5" width="281" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down Expand Up @@ -260,8 +259,8 @@
<rect key="frame" x="0.0" y="36" width="304" height="22"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Content" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qui-ab-szz">
<rect key="frame" x="15" y="0.5" width="281" height="20.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
<rect key="frame" x="15" y="2.5" width="281" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
Binary file not shown.

0 comments on commit ce80ab8

Please sign in to comment.