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

iphonex适配

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