Commit 0b1f46fd authored by 汪洋's avatar 汪洋

iphonex适配

parent f8081a03
...@@ -31,6 +31,5 @@ ...@@ -31,6 +31,5 @@
} else { } else {
return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom]; return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom];
} }
} }
@end @end
// //
// OCNavigatioinBar.h // OCNavigationBar.h
// Pods // Pods
// //
// Created by wangyang on 16/7/8. // Created by wangyang on 16/7/8.
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class OCNavigatioinBarButton; @class OCNavigationBarButton;
@protocol OCNavigatioinBarDelegate <NSObject> @protocol OCNavigationBarDelegate <NSObject>
- (void)rightButtonClicked:(OCNavigatioinBarButton *)button; - (void)rightButtonClicked:(OCNavigationBarButton *)button;
- (void)nearRightButtonClicked:(OCNavigatioinBarButton *)button; - (void)nearRightButtonClicked:(OCNavigationBarButton *)button;
- (void)backAction:(OCNavigatioinBarButton *)button; - (void)backAction:(OCNavigationBarButton *)button;
@end @end
/** /**
...@@ -21,9 +21,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -21,9 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
* *
* 作为单独组件后,导航栏按键具体值应该由业务层控制。这里不再关心 * 作为单独组件后,导航栏按键具体值应该由业务层控制。这里不再关心
*/ */
@interface OCNavigatioinBar : UIView @interface OCNavigationBar : UIView
@property (nonatomic, weak) id<OCNavigatioinBarDelegate> delegate; @property (nonatomic, weak) id<OCNavigationBarDelegate> delegate;
// OCNavigatioinBar 高度是64,itemView的y坐标从20开始,高44。titleLabel,titleView,backButton,rightButton,nearRightButton都是被添加到该itemView中的 // OCNavigationBar 高度是64,itemView的y坐标从20开始,高44。titleLabel,titleView,backButton,rightButton,nearRightButton都是被添加到该itemView中的
@property (nonatomic, strong, readonly) UIView *itemView; @property (nonatomic, strong, readonly) UIView *itemView;
@property (nonatomic, strong, readonly) UILabel *titleLabel; @property (nonatomic, strong, readonly) UILabel *titleLabel;
...@@ -31,9 +31,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -31,9 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, nullable) UIView *titleView; @property (nonatomic, strong, nullable) UIView *titleView;
@property (nonatomic, copy, nullable) NSString *title; @property (nonatomic, copy, nullable) NSString *title;
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *leftButton; @property (nonatomic, strong, readonly) OCNavigationBarButton *leftButton;
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *rightButton; @property (nonatomic, strong, readonly) OCNavigationBarButton *rightButton;
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *nearRightButton; @property (nonatomic, strong, readonly) OCNavigationBarButton *nearRightButton;
/** /**
leftIcon 有默认值:back leftIcon 有默认值:back
...@@ -51,8 +51,13 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -51,8 +51,13 @@ NS_ASSUME_NONNULL_BEGIN
- (void)hideAllItems; - (void)hideAllItems;
@end @end
@interface OCNavigationBar (ViewConstant)
@property (nonatomic, readonly, class) CGFloat barHeight;
@property (nonatomic, readonly, class) CGFloat statusBarHeight;
@property (nonatomic, readonly, class) CGFloat navigationItemCenterY;
@end
@interface OCNavigatioinBarButton : UIButton @interface OCNavigationBarButton : UIButton
@end @end
......
// //
// OCNavigatioinBar.m // OCNavigationBar.m
// Pods // Pods
// //
// Created by wangyang on 16/7/8. // Created by wangyang on 16/7/8.
// //
// //
#import "OCNavigatioinBar.h" #import "OCNavigationBar.h"
#import <Masonry/Masonry.h> #import <Masonry/Masonry.h>
#import "GMBaseUtil.h" #import "GMBaseUtil.h"
@import GMKit; @import GMKit;
@interface OCNavigatioinBarButton () @interface OCNavigationBarButton ()
@property (nonatomic, assign) CGFloat adaptiveWidth; @property (nonatomic, assign) CGFloat adaptiveWidth;
@end @end
@implementation OCNavigatioinBar { @implementation OCNavigationBar {
UIView *_shadowView; UIView *_shadowView;
} }
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
{ {
self = [super initWithFrame:frame]; self = [super initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, OCNavigationBar.barHeight)];
if (self) { if (self) {
[self setup]; [self setup];
} }
...@@ -53,9 +53,9 @@ ...@@ -53,9 +53,9 @@
_titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textColor = HEADLINE_TEXT_COLOR; _titleLabel.textColor = HEADLINE_TEXT_COLOR;
_titleLabel.font = [UIFont navigationFontWithSize:18]; _titleLabel.font = [UIFont navigationFontWithSize:18];
_leftButton = [OCNavigatioinBarButton buttonWithType:UIButtonTypeCustom]; _leftButton = [OCNavigationBarButton buttonWithType:UIButtonTypeCustom];
_rightButton = [OCNavigatioinBarButton buttonWithType:UIButtonTypeCustom]; _rightButton = [OCNavigationBarButton buttonWithType:UIButtonTypeCustom];
_nearRightButton = [OCNavigatioinBarButton buttonWithType:UIButtonTypeCustom]; _nearRightButton = [OCNavigationBarButton buttonWithType:UIButtonTypeCustom];
_titleLabel.hidden = YES; _titleLabel.hidden = YES;
self.leftIcon = @"back"; self.leftIcon = @"back";
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
}]; }];
} }
- (void)configBarButton:(OCNavigatioinBarButton *)button { - (void)configBarButton:(OCNavigationBarButton *)button {
UIColor *color = [UIColor colorWithhex:0x333333]; UIColor *color = [UIColor colorWithhex:0x333333];
[button setTitleColor:color forState:UIControlStateNormal]; [button setTitleColor:color forState:UIControlStateNormal];
button.hidden = YES; button.hidden = YES;
...@@ -108,19 +108,19 @@ ...@@ -108,19 +108,19 @@
} }
#pragma mark - Action #pragma mark - Action
- (void)leftAction:(OCNavigatioinBarButton *)button { - (void)leftAction:(OCNavigationBarButton *)button {
if ([self.delegate respondsToSelector:@selector(backAction:)]) { if ([self.delegate respondsToSelector:@selector(backAction:)]) {
[self.delegate backAction:button]; [self.delegate backAction:button];
} }
} }
- (void)rightAction:(OCNavigatioinBarButton *)button { - (void)rightAction:(OCNavigationBarButton *)button {
if ([self.delegate respondsToSelector:@selector(rightButtonClicked:)]) { if ([self.delegate respondsToSelector:@selector(rightButtonClicked:)]) {
[self.delegate rightButtonClicked:button]; [self.delegate rightButtonClicked:button];
} }
} }
- (void)nearRightAction:(OCNavigatioinBarButton *)button { - (void)nearRightAction:(OCNavigationBarButton *)button {
if ([self.delegate respondsToSelector:@selector(nearRightButtonClicked:)]) { if ([self.delegate respondsToSelector:@selector(nearRightButtonClicked:)]) {
[self.delegate nearRightButtonClicked:button]; [self.delegate nearRightButtonClicked:button];
} }
...@@ -181,10 +181,24 @@ ...@@ -181,10 +181,24 @@
[_nearRightButton setTitle:_nearRightTitle forState:UIControlStateNormal]; [_nearRightButton setTitle:_nearRightTitle forState:UIControlStateNormal];
} }
@end @end
@implementation OCNavigationBar (ViewConstant)
+ (CGFloat)barHeight {
return [self statusBarHeight] + 44;
}
+ (CGFloat)statusBarHeight {
return [UIApplication sharedApplication].statusBarFrame.size.height;
}
@implementation OCNavigatioinBarButton + (CGFloat)navigationItemCenterY {
return [self statusBarHeight] + 44/2.0;
}
@end
@implementation OCNavigationBarButton
/** /**
* @author wangyang in 2016-7-8 6.2.0 * @author wangyang in 2016-7-8 6.2.0
* *
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
[_table mas_makeConstraints:^(MASConstraintMaker *make) { [_table mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_left); make.left.equalTo(self.view.mas_left);
make.right.equalTo(self.view.mas_right); make.right.equalTo(self.view.mas_right);
make.top.mas_equalTo([UIApplication sharedApplication].statusBarFrame.size.height + 44); make.top.mas_equalTo(OCNavigationBar.barHeight);
make.bottom.equalTo(self.view.mas_safeBottom); make.bottom.equalTo(self.view.mas_safeBottom);
}]; }];
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "OCNavigatioinBar.h" #import "OCNavigationBar.h"
#import <GMPhobos/GMPhobos-umbrella.h> #import <GMPhobos/GMPhobos-umbrella.h>
@import GMKit; @import GMKit;
@interface WMBaseViewController : UIViewController <OCNavigatioinBarDelegate, GMEmptyViewDelegate> @interface WMBaseViewController : UIViewController <OCNavigationBarDelegate, GMEmptyViewDelegate>
@property (nonatomic, strong) OCNavigatioinBar *navigationBar; @property (nonatomic, strong) OCNavigationBar *navigationBar;
/** /**
默认值为NO,表示导航栏自动被WMBaseViewController管理,永远在所有的view最上方。 默认值为NO,表示导航栏自动被WMBaseViewController管理,永远在所有的view最上方。
设置为YES时表示因为特殊需求,开发人员需要自己控制导航,并且需要在viewDidLoad中确定navigationBar的位置 设置为YES时表示因为特殊需求,开发人员需要自己控制导航,并且需要在viewDidLoad中确定navigationBar的位置
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) { [_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0); make.left.mas_equalTo(0);
make.right.mas_equalTo(0); make.right.mas_equalTo(0);
make.top.mas_equalTo([UIApplication sharedApplication].statusBarFrame.size.height); make.top.mas_equalTo(OCNavigationBar.statusBarHeight);
make.bottom.mas_equalTo(0); make.bottom.mas_equalTo(0);
}]; }];
} }
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
#pragma mark - 导航 #pragma mark - 导航
- (void)customNavigationBar { - (void)customNavigationBar {
_navigationBar = [[OCNavigatioinBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIApplication sharedApplication].statusBarFrame.size.height + 44)]; _navigationBar = [OCNavigationBar new];
} }
- (void)addNavigationBar { - (void)addNavigationBar {
...@@ -139,10 +139,10 @@ ...@@ -139,10 +139,10 @@
[self.navigationController pushViewController:controller animated:YES]; [self.navigationController pushViewController:controller animated:YES];
} }
#pragma mark - OCNavigatioinBarDelegate #pragma mark - OCNavigationBarDelegate
- (void)nearRightButtonClicked:(OCNavigatioinBarButton *)button {} - (void)nearRightButtonClicked:(OCNavigationBarButton *)button {}
- (void)rightButtonClicked:(OCNavigatioinBarButton *)button {} - (void)rightButtonClicked:(OCNavigationBarButton *)button {}
- (void)backAction:(OCNavigatioinBarButton *)button { - (void)backAction:(OCNavigationBarButton *)button {
if ([self.parentViewController isKindOfClass:[UINavigationController class]]) { if ([self.parentViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigation = (UINavigationController *)self.parentViewController; UINavigationController *navigation = (UINavigationController *)self.parentViewController;
NSArray *controllers = navigation.viewControllers; NSArray *controllers = navigation.viewControllers;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment