Browse Source

自定义键盘输入框

Chris 5 years ago
parent
commit
a46a9ffb06

+ 46 - 0
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -369,6 +369,11 @@
 		BD1FC18622B09F9800D55081 /* CommunitySubCommentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC18522B09F9800D55081 /* CommunitySubCommentController.swift */; };
 		BD1FC18822B0A30300D55081 /* CommunityMajorCommentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC18722B0A30300D55081 /* CommunityMajorCommentCell.swift */; };
 		BD1FC18A22B0A32100D55081 /* CommunityReplyCommentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC18922B0A32100D55081 /* CommunityReplyCommentCell.swift */; };
+		BD1FC1A322B1075F00D55081 /* UIView+LX_Frame.m in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC19922B1075F00D55081 /* UIView+LX_Frame.m */; };
+		BD1FC1A622B1075F00D55081 /* LxButton.m in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC19C22B1075F00D55081 /* LxButton.m */; };
+		BD1FC1A722B1075F00D55081 /* UIColor+Expanded.m in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC19E22B1075F00D55081 /* UIColor+Expanded.m */; };
+		BD1FC1A822B1075F00D55081 /* LXTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC1A022B1075F00D55081 /* LXTextView.m */; };
+		BD1FC1A922B1075F00D55081 /* LXKeyBoard.m in Sources */ = {isa = PBXBuildFile; fileRef = BD1FC1A122B1075F00D55081 /* LXKeyBoard.m */; };
 		BD20F1CB2283C12000677D8E /* ShoppingCartListNoneItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD20F1CA2283C12000677D8E /* ShoppingCartListNoneItemCell.swift */; };
 		BD20F1CD2283C51300677D8E /* OrderFinishPayController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD20F1CC2283C51300677D8E /* OrderFinishPayController.swift */; };
 		BD20F1CF2283CE2300677D8E /* OrderFinishPayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD20F1CE2283CE2300677D8E /* OrderFinishPayView.swift */; };
@@ -816,6 +821,16 @@
 		BD1FC18522B09F9800D55081 /* CommunitySubCommentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunitySubCommentController.swift; sourceTree = "<group>"; };
 		BD1FC18722B0A30300D55081 /* CommunityMajorCommentCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityMajorCommentCell.swift; sourceTree = "<group>"; };
 		BD1FC18922B0A32100D55081 /* CommunityReplyCommentCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityReplyCommentCell.swift; sourceTree = "<group>"; };
+		BD1FC19122B1075E00D55081 /* LXTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LXTextView.h; sourceTree = "<group>"; };
+		BD1FC19522B1075E00D55081 /* UIView+LX_Frame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+LX_Frame.h"; sourceTree = "<group>"; };
+		BD1FC19722B1075F00D55081 /* LxButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LxButton.h; sourceTree = "<group>"; };
+		BD1FC19822B1075F00D55081 /* UIColor+Expanded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Expanded.h"; sourceTree = "<group>"; };
+		BD1FC19922B1075F00D55081 /* UIView+LX_Frame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+LX_Frame.m"; sourceTree = "<group>"; };
+		BD1FC19C22B1075F00D55081 /* LxButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LxButton.m; sourceTree = "<group>"; };
+		BD1FC19E22B1075F00D55081 /* UIColor+Expanded.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Expanded.m"; sourceTree = "<group>"; };
+		BD1FC19F22B1075F00D55081 /* LXKeyBoard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LXKeyBoard.h; sourceTree = "<group>"; };
+		BD1FC1A022B1075F00D55081 /* LXTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LXTextView.m; sourceTree = "<group>"; };
+		BD1FC1A122B1075F00D55081 /* LXKeyBoard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LXKeyBoard.m; sourceTree = "<group>"; };
 		BD20F1CA2283C12000677D8E /* ShoppingCartListNoneItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartListNoneItemCell.swift; sourceTree = "<group>"; };
 		BD20F1CC2283C51300677D8E /* OrderFinishPayController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderFinishPayController.swift; sourceTree = "<group>"; };
 		BD20F1CE2283CE2300677D8E /* OrderFinishPayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderFinishPayView.swift; sourceTree = "<group>"; };
@@ -2302,6 +2317,7 @@
 		A77F2CBC2232022A001BD3F6 /* Tools */ = {
 			isa = PBXGroup;
 			children = (
+				BD1FC19022B1075E00D55081 /* CommentKeyboard */,
 				A7931DF422AF827600297D0A /* ESTabBarController-swift */,
 				BD108C8D22A60A2000837DAB /* HGImagePicker */,
 				A7391212229F75F50033177E /* JXPagingView-Swift */,
@@ -3178,6 +3194,31 @@
 			path = CommunitySubComment;
 			sourceTree = "<group>";
 		};
+		BD1FC19022B1075E00D55081 /* CommentKeyboard */ = {
+			isa = PBXGroup;
+			children = (
+				BD1FC19222B1075E00D55081 /* Category */,
+				BD1FC19F22B1075F00D55081 /* LXKeyBoard.h */,
+				BD1FC1A122B1075F00D55081 /* LXKeyBoard.m */,
+				BD1FC19122B1075E00D55081 /* LXTextView.h */,
+				BD1FC1A022B1075F00D55081 /* LXTextView.m */,
+			);
+			path = CommentKeyboard;
+			sourceTree = "<group>";
+		};
+		BD1FC19222B1075E00D55081 /* Category */ = {
+			isa = PBXGroup;
+			children = (
+				BD1FC19722B1075F00D55081 /* LxButton.h */,
+				BD1FC19C22B1075F00D55081 /* LxButton.m */,
+				BD1FC19822B1075F00D55081 /* UIColor+Expanded.h */,
+				BD1FC19E22B1075F00D55081 /* UIColor+Expanded.m */,
+				BD1FC19522B1075E00D55081 /* UIView+LX_Frame.h */,
+				BD1FC19922B1075F00D55081 /* UIView+LX_Frame.m */,
+			);
+			path = Category;
+			sourceTree = "<group>";
+		};
 		BD3474F722859788000908C5 /* OrderPayOrder */ = {
 			isa = PBXGroup;
 			children = (
@@ -3665,6 +3706,7 @@
 				A7274C5E228EE636000E3A07 /* LBXPermissions.swift in Sources */,
 				A7D46092227619CD00A5A54E /* BaiduToCityFactory.swift in Sources */,
 				A71AA51C227219EF008FF1A5 /* EditExpressAddressView.swift in Sources */,
+				BD1FC1A822B1075F00D55081 /* LXTextView.m in Sources */,
 				BDAA40FB228E9CC300CF841D /* OrderApplyRefundNoteInfoCell.swift in Sources */,
 				A7DF50D622A4E8B400998908 /* OrderDetailProductTableViewCell.swift in Sources */,
 				A7CC751122715AE3003C4F38 /* MessageDetailesTimeView.swift in Sources */,
@@ -3677,6 +3719,7 @@
 				BDF47D7E22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift in Sources */,
 				BD108C9522A60C2100837DAB /* HGImageCollectionViewCell.swift in Sources */,
 				A7FF1589228C854900A85748 /* OrderDetailBottomView.swift in Sources */,
+				BD1FC1A722B1075F00D55081 /* UIColor+Expanded.m in Sources */,
 				BD12203122AF4A010051C7C2 /* MessageMainItemView.swift in Sources */,
 				BD1DC6C5228CFD0B00B89C57 /* SwiftMoyaNetWorkServiceOrder.swift in Sources */,
 				BD7AB83D228438020030646A /* OrderPayExpressInfoShowCell.swift in Sources */,
@@ -3744,6 +3787,7 @@
 				A70B2C60228870CE00B2449F /* ShopSectionHeaderView.swift in Sources */,
 				A7CC7528227196C4003C4F38 /* AccountSecuritySetTableViewCell.swift in Sources */,
 				A70B2C292286D77200B2449F /* ProductDetailProductInfoTableViewCell.swift in Sources */,
+				BD1FC1A922B1075F00D55081 /* LXKeyBoard.m in Sources */,
 				A72A726822321DBD00B21995 /* UMManager.swift in Sources */,
 				A70B2C042283D06B00B2449F /* ProductFloorFullLeftHeaderCollectionReusableView.swift in Sources */,
 				BD108C9322A60C2100837DAB /* HGImageCompleteButton.swift in Sources */,
@@ -3793,6 +3837,7 @@
 				BDF862AA228E43A4000DEF84 /* OrderCommentTableViewCell.swift in Sources */,
 				A7B4E754228278320012914A /* ShoppingMallFloorTableViewCell.swift in Sources */,
 				BD3474F522857B85000908C5 /* CommonPayHeader.swift in Sources */,
+				BD1FC1A322B1075F00D55081 /* UIView+LX_Frame.m in Sources */,
 				A71AF0B6226EF99A001730FE /* SearchResultViewController.swift in Sources */,
 				A757C9302274839900226355 /* SelfMentionAddressListModel.swift in Sources */,
 				BDD22F0B228FAA5B00D43BFB /* ImageUrlModel.swift in Sources */,
@@ -3912,6 +3957,7 @@
 				A7B4E73A228192D20012914A /* CMSTemplateModel.swift in Sources */,
 				A72A72C622321DE000B21995 /* WebView.swift in Sources */,
 				A72A72D122321E2700B21995 /* HTMLURLMacro.swift in Sources */,
+				BD1FC1A622B1075F00D55081 /* LxButton.m in Sources */,
 				BDF862A1228E41CC000DEF84 /* OrderLogisticsController.swift in Sources */,
 				A72A73162232481600B21995 /* WeChatpayManager.swift in Sources */,
 				A7CC750F22715AAC003C4F38 /* MessageDetailesTableViewCell.swift in Sources */,

+ 4 - 0
RainbowPlanet/RainbowPlanet/Macro/RainbowPlanet-Bridging-Header.h

@@ -51,4 +51,8 @@
 #import <BaiduMapAPI_Map/BMKMapView.h>
 
 
+// FIXME: 自定义键盘--待转swift
+#import "LXKeyBoard.h"
+
+
 #endif /* RainbowPlanet_Bridging_Header_h */

+ 24 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunitySubComment/CommunitySubCommentController.swift

@@ -14,7 +14,14 @@ class CommunitySubCommentController: BaseViewController {
         super.viewDidLoad()
         setupViews()
         setupLayouts()
-        
+    }
+    
+    override func viewWillAppear(_ animated: Bool) {
+        cmtKeyboard.isDisappear = false
+    }
+    
+    override func viewWillDisappear(_ animated: Bool) {
+        cmtKeyboard.isDisappear = true
     }
     
     override func setupViews() {
@@ -22,6 +29,7 @@ class CommunitySubCommentController: BaseViewController {
         view.backgroundColor = kf7f8faColor
         
         view.addSubview(tableView)
+        view.addSubview(cmtKeyboard)
     }
     
     override func setupLayouts() {
@@ -46,6 +54,21 @@ class CommunitySubCommentController: BaseViewController {
         tableView.estimatedSectionHeaderHeight = 0.000001
         return tableView
     }()
+    
+    lazy var cmtKeyboard: LXKeyBoard = {
+        let cmtKeyboard = LXKeyBoard.init()
+        cmtKeyboard.backgroundColor = kffffffColor
+        cmtKeyboard.maxLine = 3
+        cmtKeyboard.font = kRegularFont14
+        cmtKeyboard.topOrBottomEdge = 10
+        cmtKeyboard.beginUpdateUI()
+        cmtKeyboard.sendBlock = {
+            [weak self] (text) in
+            print("----\(text)")
+        }
+        
+        return cmtKeyboard
+    }()
 }
 
 // MARK: - tableView dataSource && delegate

+ 26 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/Category/LxButton.h

@@ -0,0 +1,26 @@
+//
+//  LxButton.h
+//  ButtonBlock
+//
+//  Created by chuanglong02 on 16/8/4.
+//  Copyright © 2016年 chuanglong02. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+#define  Font(f) [UIFont systemFontOfSize:(f)]
+#define LXWS(weakSelf)  __weak __typeof(&*self)weakSelf = self
+typedef void (^ButtonBlock)(UIButton *button);
+
+@interface LxButton : UIButton
+@property(nonatomic,copy)ButtonBlock block;
+@property(nonatomic,assign)NSInteger buttonID;
+
+@property(nonatomic,assign)CGSize enlargeSize;
+
+-(void)addClickBlock:(ButtonBlock)block;
+
++(LxButton *)LXButtonWithTitle:(NSString *)title  titleFont:(UIFont *)titleLabelFont Image:(UIImage *)image backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleLabelColor frame:(CGRect)frame;
+
++(LxButton *)LXButtonNoFrameWithTitle:(NSString *)title  titleFont:(UIFont *)titleLabelFont Image:(UIImage *)image backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleLabelColor;
+@end

+ 65 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/Category/LxButton.m

@@ -0,0 +1,65 @@
+//
+//  LxButton.m
+//  ButtonBlock
+//
+//  Created by chuanglong02 on 16/8/4.
+//  Copyright © 2016年 chuanglong02. All rights reserved.
+//
+
+#import "LxButton.h"
+
+@implementation LxButton
++(LxButton *)LXButtonWithTitle:(NSString *)title titleFont:(UIFont *)titleLabelFont Image:(UIImage *)image backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleLabelColor frame:(CGRect)frame
+{
+    LxButton *button = [LxButton buttonWithType:UIButtonTypeCustom];
+    [button setImage:image forState:UIControlStateNormal];
+    [button setBackgroundImage:backgroundImage forState:UIControlStateNormal];
+    [button setTitle:title forState:UIControlStateNormal];
+    [button setTitleColor:titleLabelColor forState:UIControlStateNormal];
+    button.backgroundColor = backgroundColor;
+    button.frame = frame;
+    button.titleLabel.font = titleLabelFont;
+    return button;
+}
++(LxButton *)LXButtonNoFrameWithTitle:(NSString *)title titleFont:(UIFont *)titleLabelFont Image:(UIImage *)image backgroundImage:(UIImage *)backgroundImage backgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleLabelColor
+{
+    LxButton *button = [LxButton buttonWithType:UIButtonTypeCustom];
+    [button setImage:image forState:UIControlStateNormal];
+    [button setBackgroundImage:backgroundImage forState:UIControlStateNormal];
+    [button setTitle:title forState:UIControlStateNormal];
+    [button setTitleColor:titleLabelColor forState:UIControlStateNormal];
+    button.backgroundColor = backgroundColor;
+    button.titleLabel.font = titleLabelFont;
+    return button;
+}
+
+-(void)addClickBlock:(ButtonBlock)block
+{
+    _block = block;
+    [self addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
+}
+-(void)buttonAction:(UIButton *)button
+{
+    _block(button);
+}
+-(void)setButtonID:(NSInteger)buttonID
+{
+    _buttonID = buttonID;
+    self.tag = buttonID;
+}
+
+-(void)setEnlargeSize:(CGSize)enlargeSize{
+    _enlargeSize = enlargeSize;
+}
+-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
+{
+    CGRect bounds = self.bounds;
+    //扩大原热区直径至26,可以暴露个接口,用来设置需要扩大的半径。
+    
+    CGFloat widthDelta = MAX(self.enlargeSize.width , 0);
+    CGFloat heightDelta = MAX(self.enlargeSize.height, 0);
+    bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta);
+    return CGRectContainsPoint(bounds, point);
+}
+
+@end

+ 21 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/Category/UIColor+Expanded.h

@@ -0,0 +1,21 @@
+//
+//  UIColor+HexStringToColor.h
+//  SmartGate
+//
+//  Created by fred on 14-8-19.
+//  Copyright (c) 2014年 fred. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface UIColor (Expanded)
+
++(UIColor *) hexStringToColor: (NSString *) stringToConvert;
++(UIColor *) hexStringToColor: (NSString *) stringToConvert andAlpha:(CGFloat)alpha;
+
++(UIColor *)defaultBackGroundColor;
++(UIColor *)commonBackGroundColor;
++(UIColor *)defaultTitleWordColor;
++(UIColor *)defaultContentWordColor;
+
+@end

+ 76 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/Category/UIColor+Expanded.m

@@ -0,0 +1,76 @@
+//
+//  UIColor+HexStringToColor.m
+//  SmartGate
+//
+//  Created by fred on 14-8-19.
+//  Copyright (c) 2014年 fred. All rights reserved.
+//
+
+#import "UIColor+Expanded.h"
+
+@implementation UIColor (Expanded)
+
++(UIColor *) hexStringToColor: (NSString *) stringToConvert
+{
+    return [UIColor hexStringToColor:stringToConvert andAlpha:1.0];
+}
+
++(UIColor *) hexStringToColor: (NSString *) stringToConvert andAlpha:(CGFloat)alpha
+{
+    NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
+    
+    // String should be 6 or 8 characters
+    if ([cString length] < 6) return [UIColor clearColor];
+    // strip 0X if it appears
+    if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
+    if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
+    if ([cString length] != 6) return [UIColor clearColor];
+    
+    // Separate into r, g, b substrings
+    
+    NSRange range;
+    range.location = 0;
+    range.length = 2;
+    NSString *rString = [cString substringWithRange:range];
+    range.location = 2;
+    NSString *gString = [cString substringWithRange:range];
+    range.location = 4;
+    NSString *bString = [cString substringWithRange:range];
+    // Scan values
+    unsigned int r, g, b;
+    
+    if (alpha >1.0 || alpha < 0) {
+        alpha = 1.0;
+    }
+    
+    [[NSScanner scannerWithString:rString] scanHexInt:&r];
+    [[NSScanner scannerWithString:gString] scanHexInt:&g];
+    [[NSScanner scannerWithString:bString] scanHexInt:&b];
+    
+    return [UIColor colorWithRed:((float) r / 255.0f)
+                           green:((float) g / 255.0f)
+                            blue:((float) b / 255.0f)
+                           alpha:alpha];
+}
+
++(UIColor *)commonBackGroundColor
+{
+   return  [self hexStringToColor:@"F2F2F2"];
+}
+
++(UIColor *)defaultBackGroundColor
+{
+    return  [self hexStringToColor:@"2B569A"];
+}
+
++(UIColor *)defaultTitleWordColor
+{
+    return  [self hexStringToColor:@"666666"];
+}
+
++(UIColor *)defaultContentWordColor
+{
+    return  [self hexStringToColor:@"2B569A"];
+}
+
+@end

+ 26 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/Category/UIView+LX_Frame.h

@@ -0,0 +1,26 @@
+//
+//  UIView+LX_Frame.h
+//  AliPayHome
+//
+//  Created by chenergou on 2017/10/31.
+//  Copyright © 2017年 漫漫. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface UIView (LX_Frame)
+@property (assign, nonatomic) CGFloat lx_x;
+@property (assign, nonatomic) CGFloat lx_y;
+@property (assign, nonatomic) CGFloat lx_width;
+@property (assign, nonatomic) CGFloat lx_height;
+
+@property (assign, nonatomic) CGFloat lx_left;
+@property (assign, nonatomic) CGFloat lx_top;
+@property (assign, nonatomic) CGFloat lx_right;
+@property (assign, nonatomic) CGFloat lx_bottom;
+
+@property (assign, nonatomic) CGSize lx_size;
+@property (assign, nonatomic) CGFloat lx_centerX;
+@property (assign, nonatomic) CGFloat lx_centerY;
+
+@end

+ 111 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/Category/UIView+LX_Frame.m

@@ -0,0 +1,111 @@
+//
+//  UIView+LX_Frame.m
+//  AliPayHome
+//
+//  Created by chenergou on 2017/10/31.
+//  Copyright © 2017年 漫漫. All rights reserved.
+//
+
+#import "UIView+LX_Frame.h"
+
+@implementation UIView (LX_Frame)
+-(void)setLx_x:(CGFloat)lx_x{
+        CGFloat y = self.frame.origin.y;
+        CGFloat width = self.frame.size.width;
+        CGFloat height = self.frame.size.height;
+        self.frame = CGRectMake(lx_x, y, width, height);
+}
+-(CGFloat)lx_x{
+    return self.frame.origin.x;
+}
+-(void)setLx_y:(CGFloat)lx_y{
+    CGFloat x = self.frame.origin.x;
+    CGFloat width = self.frame.size.width;
+    CGFloat height = self.frame.size.height;
+    self.frame = CGRectMake(x, lx_y, width, height);
+}
+-(CGFloat)lx_y{
+    return self.frame.origin.y;
+}
+-(void)setLx_width:(CGFloat)lx_width{
+    CGRect frame = self.frame;
+    frame.size.width = lx_width;
+    self.frame = frame;
+}
+-(CGFloat)lx_width{
+    return self.frame.size.width;
+}
+
+-(void)setLx_height:(CGFloat)lx_height{
+    CGRect frame = self.frame;
+    frame.size.height = lx_height;
+    self.frame = frame;
+}
+
+-(CGFloat)lx_height{
+    return self.frame.size.height;
+}
+
+
+-(void)setLx_left:(CGFloat)lx_left{
+    CGFloat y = self.frame.origin.y;
+    CGFloat width = self.frame.size.width;
+    CGFloat height = self.frame.size.height;
+    self.frame = CGRectMake(lx_left, y, width, height);
+}
+-(CGFloat)lx_left{
+    return self.frame.origin.x;
+}
+
+
+-(void)setLx_top:(CGFloat)lx_top{
+    CGFloat x = self.frame.origin.x;
+    CGFloat width = self.frame.size.width;
+    CGFloat height = self.frame.size.height;
+    self.frame = CGRectMake(x, lx_top, width, height);
+}
+-(CGFloat)lx_top{
+    return self.frame.origin.y;
+}
+-(void)setLx_right:(CGFloat)lx_right{
+    CGRect frame = self.frame;
+    frame.origin.x = lx_right - frame.size.width;
+    self.frame = frame;
+}
+-(CGFloat)lx_right{
+    return self.frame.origin.x + self.frame.size.width;
+}
+-(void)setLx_bottom:(CGFloat)lx_bottom{
+    CGRect frame = self.frame;
+    frame.origin.y = lx_bottom - frame.size.height;
+    self.frame = frame;
+}
+-(CGFloat)lx_bottom{
+     return self.frame.origin.y + self.frame.size.height;
+}
+
+-(CGSize)lx_size {
+    return self.frame.size;
+}
+
+- (void)setLx_size:(CGSize)lx_size {
+    CGRect frame = self.frame;
+    frame.size = lx_size;
+    self.frame = frame;
+}
+-(CGFloat)lx_centerX{
+    return self.center.x;
+}
+-(void)setLx_centerX:(CGFloat)lx_centerX{
+    
+    self.center = CGPointMake(lx_centerX, self.center.y);
+   
+}
+-(CGFloat)lx_centerY{
+    return self.center.y;
+
+}
+-(void)setLx_centerY:(CGFloat)lx_centerY{
+    self.center = CGPointMake(self.center.x, lx_centerY);
+}
+@end

+ 30 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/LXKeyBoard.h

@@ -0,0 +1,30 @@
+//
+//  LXKeyBoard.h
+//  LXKeyBoardTextView
+//
+//  Created by chenergou on 2017/12/21.
+//  Copyright © 2017年 漫漫. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+typedef void (^SendBlock) (NSString *text);
+@interface LXKeyBoard : UIView
+/**
+ 
+ 需要配置的属性(也可不传)
+ 
+ */
+@property(nonatomic,assign)BOOL isDisappear;//是否即将消失。
+@property(nonatomic,assign)int maxLine;//设置最大行数
+@property(nonatomic,assign)CGFloat topOrBottomEdge;//上下间距
+@property(nonatomic,strong)UIFont *font;//设置字体大小(决定输入框的初始高度)
+
+
+//设置好属性之后开始布局
+-(void)beginUpdateUI;
+
+
+//回调
+@property(nonatomic,copy)SendBlock sendBlock;
+@end

+ 249 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/LXKeyBoard.m

@@ -0,0 +1,249 @@
+//
+//  LXKeyBoard.m
+//  LXKeyBoardTextView
+//
+//  Created by chenergou on 2017/12/21.
+//  Copyright © 2017年 漫漫. All rights reserved.
+//
+
+#import "LXKeyBoard.h"
+#import "LXTextView.h"
+
+#import "LxButton.h"
+#import "UIColor+Expanded.h"
+#import "UIView+LX_Frame.h"
+
+#define Device_Width  [[UIScreen mainScreen] bounds].size.width
+#define Device_Height [[UIScreen mainScreen] bounds].size.height
+
+@interface LXKeyBoard()<UITextViewDelegate>
+@property(nonatomic,strong)LXTextView *textView;
+@property(nonatomic,strong)LxButton *sendBtn;
+@end
+@implementation LXKeyBoard
+{
+    CGFloat keyboardY;
+    
+}
+
+-(void)awakeFromNib{
+    [super awakeFromNib];
+    
+    [[NSNotificationCenter defaultCenter]removeObserver:self];
+    self.layer.borderWidth = 1;
+    self.layer.borderColor =[UIColor hexStringToColor:@"A5A5A5"].CGColor;
+    
+    
+    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
+    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];;
+    
+    //设置默认属性
+    self.topOrBottomEdge = 8;
+    self.font = Font(18);
+    self.maxLine = 3;
+}
+-(instancetype)initWithFrame:(CGRect)frame{
+    self =  [super initWithFrame:frame];
+    
+    
+    if (self) {
+        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
+        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
+        //设置默认属性
+        self.topOrBottomEdge = 10;
+        self.font = Font(14);
+        self.maxLine = 3;
+        
+    }
+    return self;
+}
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
+        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
+        //设置默认属性
+        self.topOrBottomEdge = 10;
+        self.font = Font(14);
+        self.maxLine = 3;
+    }
+    return self;
+}
+-(void)dealloc{
+    [[NSNotificationCenter defaultCenter]removeObserver:self];
+    NSLog(@"%@",self.class);
+}
+
+
+-(void)beginUpdateUI{
+    //初始化高度 textView的lineHeight + 2 * 上下间距
+    CGFloat orignTextH  = 28 + 2 * self.topOrBottomEdge;
+    
+    self.frame = CGRectMake(0, Device_Height - orignTextH, Device_Width, orignTextH);
+    
+    [self setup];
+}
+-(void)setup{
+    [self addSubview:self.textView];
+    [self addSubview:self.sendBtn];
+    
+    LXWS(weakSelf);
+    [self.sendBtn addClickBlock:^(UIButton *button) {
+        
+        if (weakSelf.sendBlock) {
+            weakSelf.sendBlock(weakSelf.textView.text);
+        }
+    }];
+}
+-(void)textViewDidChange:(UITextView *)textView{
+    
+    CGFloat contentSizeH = self.textView.contentSize.height;
+    CGFloat lineH = self.textView.font.lineHeight;
+    
+    CGFloat maxHeight = ceil(lineH * self.maxLine + textView.textContainerInset.top + textView.textContainerInset.bottom);
+    if (contentSizeH <= maxHeight) {
+        self.textView.lx_height = contentSizeH;
+    }else{
+        self.textView.lx_height = maxHeight;
+    }
+    
+    [textView scrollRangeToVisible:NSMakeRange(textView.selectedRange.location, 1)];
+    
+    
+    CGFloat totalH = ceil(self.textView.lx_height) + 2 * self.topOrBottomEdge;
+    self.frame = CGRectMake(0, keyboardY - totalH, self.lx_width, totalH);
+    
+    
+    if (self.lx_height-38 < 10) {
+        self.sendBtn.lx_y = 10;
+    } else {
+        self.sendBtn.lx_y = self.lx_height-38;
+    }
+    
+    
+    if (textView.text.length > 0) {
+        _sendBtn.backgroundColor = [UIColor hexStringToColor:@"62cc74"];
+    } else {
+        _sendBtn.backgroundColor = [UIColor hexStringToColor:@"d8d8d8"];
+    }
+    
+}
+-(void)keyboardWillChangeFrame:(NSNotification *)notification{
+    
+    NSDictionary *userInfo = notification.userInfo;
+    // 动画的持续时间
+    double duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
+    
+    // 键盘的frame
+    CGRect keyboardF = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
+    //        NSLog(@"%@",NSStringFromCGRect(keyboardF));
+    keyboardY = keyboardF.origin.y;
+    
+    if (!_isDisappear) {
+        
+        [self dealKeyBoardWithKeyboardF:keyboardY duration:duration];
+        
+    }
+    
+    
+}
+
+-(void)keyboardDidChangeFrame:(NSNotification *)notification{
+    
+    NSDictionary *userInfo = notification.userInfo;
+    // 动画的持续时间
+    double duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
+    // 键盘的frame
+    CGRect keyboardF = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
+    //        NSLog(@"%@",NSStringFromCGRect(keyboardF));
+    
+    keyboardY = keyboardF.origin.y;
+    //    // 工具条的Y值 == 键盘的Y值 - 工具条的高度
+    if (_isDisappear) {
+        [self dealKeyBoardWithKeyboardF:keyboardY duration:duration];
+    }
+    
+}
+#pragma mark---处理高度---
+-(void)dealKeyBoardWithKeyboardF:(CGFloat)keyboardY duration:(CGFloat)duration {
+    
+    if (!_isDisappear) {
+        [UIView animateWithDuration:duration animations:^{
+            // 工具条的Y值 == 键盘的Y值 - 工具条的高度
+            
+            if (keyboardY > Device_Height) {
+                self.lx_y = Device_Height- self.lx_height;
+            }else
+            {
+                self.lx_y = keyboardY - self.lx_height;
+            }
+        }];
+    }else{
+        if (keyboardY > Device_Height) {
+            self.lx_y = Device_Height- self.lx_height;
+        }else
+        {
+            self.lx_y = keyboardY - self.lx_height;
+        }
+    }
+    
+    
+}
+#pragma mark---setter---
+-(void)setTopOrBottomEdge:(CGFloat)topOrBottomEdge{
+    _topOrBottomEdge  = topOrBottomEdge;
+    
+    if (!_topOrBottomEdge) {
+        topOrBottomEdge = 10;
+    }
+}
+-(void)setMaxLine:(int)maxLine{
+    _maxLine = maxLine;
+    
+    if (!_maxLine || _maxLine <=0) {
+        _maxLine = 3;
+    }
+    
+}
+-(void)setFont:(UIFont *)font{
+    _font = font;
+    if (!font) {
+        _font = Font(16);
+    }
+}
+-(void)setIsDisappear:(BOOL)isDisappear{
+    _isDisappear = isDisappear;
+}
+
+
+#pragma mark---getter---
+-(LXTextView *)textView{
+    if (!_textView) {
+        _textView =[[LXTextView alloc]initWithFrame:CGRectMake(14, self.topOrBottomEdge, self.lx_width-89-14, 28)];
+        _textView.backgroundColor = [UIColor hexStringToColor:@"fafafa"];
+        _textView.font = self.font;
+        _textView.delegate = self;
+        _textView.layoutManager.allowsNonContiguousLayout = NO;
+        _textView.enablesReturnKeyAutomatically = YES;
+        _textView.scrollsToTop = NO;
+        // 关闭textview的默认间距属性
+        //        _textView.textContainerInset = UIEdgeInsetsZero;
+        _textView.textContainerInset = UIEdgeInsetsMake(4, 15, 4, 0);
+        
+        _textView.textContainer.lineFragmentPadding = 0;
+        _textView.layer.cornerRadius = 15;
+        _textView.layer.masksToBounds = YES;
+        _textView.placeholder = @"添加评论:";
+    }
+    return _textView;
+}
+-(LxButton *)sendBtn{
+    if (!_sendBtn) {
+        _sendBtn =[LxButton LXButtonWithTitle:@"发布" titleFont:Font(14) Image:nil backgroundImage:nil backgroundColor:[UIColor hexStringToColor:@"d8d8d8"] titleColor:[UIColor whiteColor] frame:CGRectMake(self.lx_width - 74, 10, 60, 28)];
+        _sendBtn.layer.cornerRadius = 16;
+        _sendBtn.layer.masksToBounds = YES;
+    }
+    return _sendBtn;
+}
+@end

+ 17 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/LXTextView.h

@@ -0,0 +1,17 @@
+//
+//  LXTextView.h
+//  UITextViewPlaceholderView
+//
+//  Created by idMac2 on 16/1/21.
+//  Copyright © 2016年 idMac2. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface LXTextView : UITextView
+/** 占位文字 */
+@property (nonatomic, copy) NSString *placeholder;
+/** 占位文字的颜色 */
+@property (nonatomic, strong) UIColor *placeholderColor;
+@end
+

+ 104 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentKeyboard/LXTextView.m

@@ -0,0 +1,104 @@
+//
+//  LXTextView.m
+//  UITextViewPlaceholderView
+//
+//  Created by idMac2 on 16/1/21.
+//  Copyright © 2016年 idMac2. All rights reserved.
+//
+
+#import "LXTextView.h"
+//通知中心
+#define LXNotificationCenter [NSNotificationCenter defaultCenter]
+@implementation LXTextView
+-(void)awakeFromNib{
+    [super awakeFromNib];
+    // 通知
+    // 当UITextView的文字发生改变时,UITextView自己会发出一个UITextViewTextDidChangeNotification通知
+    [LXNotificationCenter addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self];
+}
+- (id)initWithFrame:(CGRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        // 不要设置自己的delegate为自己
+        //        self.delegate = self;
+        
+        if (@available(iOS 11.0, *)) {
+            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
+        }
+        // 通知
+        // 当UITextView的文字发生改变时,UITextView自己会发出一个UITextViewTextDidChangeNotification通知
+        [LXNotificationCenter addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self];
+        
+    }
+    return self;
+}
+
+
+- (void)dealloc
+{
+    [LXNotificationCenter removeObserver:self];
+}
+
+/**
+ * 监听文字改变
+ */
+- (void)textDidChange
+{
+    // 重绘(重新调用)
+    [self setNeedsDisplay];
+}
+
+- (void)setPlaceholder:(NSString *)placeholder
+{
+    _placeholder = [placeholder copy];
+    
+    [self setNeedsDisplay];
+}
+
+- (void)setPlaceholderColor:(UIColor *)placeholderColor
+{
+    _placeholderColor = placeholderColor;
+    
+    [self setNeedsDisplay];
+}
+
+- (void)setText:(NSString *)text
+{
+    [super setText:text];
+    
+    // setNeedsDisplay会在下一个消息循环时刻,调用drawRect:
+    [self setNeedsDisplay];
+}
+
+- (void)setFont:(UIFont *)font
+{
+    [super setFont:font];
+    
+    [self setNeedsDisplay];
+}
+
+- (void)drawRect:(CGRect)rect
+{
+    //    [HWRandomColor set];
+    //    UIRectFill(CGRectMake(20, 20, 30, 30));
+    // 如果有输入文字,就直接返回,不画占位文字
+    
+    
+    if (self.hasText) return;
+    
+    // 文字属性
+    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
+    attrs[NSFontAttributeName] = self.font;
+    attrs[NSForegroundColorAttributeName] = self.placeholderColor?self.placeholderColor:[UIColor grayColor];
+    // 画文字
+    //    [self.placeholder drawAtPoint:CGPointMake(5, 8) withAttributes:attrs];
+    CGFloat x = 15;
+    CGFloat w = rect.size.width - 2 * x;
+    CGFloat y = 4;
+    CGFloat h = rect.size.height - 2 * y;
+    CGRect placeholderRect = CGRectMake(x, y, w, h);
+    [self.placeholder drawInRect:placeholderRect withAttributes:attrs];
+}
+
+@end