Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,46 @@
//
// UMComCommentEditView.h
// UMCommunity
//
// Created by umeng on 15/7/22.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UMComSimpleCommentEditView : NSObject
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) UITextField *commentTextField;
@property (nonatomic, assign) NSInteger maxTextLenght;
@property (nonatomic, strong) UIView *commentInputView;
@property (nonatomic, strong) UIButton *favoriteButton;
@property (nonatomic, strong) UIButton *likeButton;
@property (nonatomic, strong) UIButton *sendButton;
@property (nonatomic, assign) BOOL isReply;
@property (nonatomic, copy) void (^SendCommentHandler)(NSString *content);
@property (nonatomic, copy) void (^clickOnLikeButtonBlock)(UIButton *likeButton);
@property (nonatomic, copy) void (^clickOnFavoriteButtonBlock)(UIButton *favoriteButton);
- (instancetype)initWithSuperView:(UIView *)view;
-(void)presentEditView;
- (void)dismissKeyboard;
- (void)addAllEditView;
- (void)removeAllEditView;
@end
@@ -0,0 +1,305 @@
//
// UMComCommentEditView.m
// UMCommunity
//
// Created by umeng on 15/7/22.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import "UMComSimpleCommentEditView.h"
#import "UMComResouceDefines.h"
#import "UMComShowToast.h"
#import <UMCommunitySDK/UMComSession.h>
#import <UMComFoundation/UMComKit+Color.h>
@interface UMComSimpleCommentEditView ()<UITextFieldDelegate>
@property (nonatomic, strong) UILabel *noticeLabel;
@property (nonatomic, strong) NSString *lastText;
@property (nonatomic, strong) UIView *mySuperView;
@end
@implementation UMComSimpleCommentEditView
- (instancetype)initWithSuperView:(UIView *)view
{
self = [super init];
if (self) {
self.view = [[UIView alloc]initWithFrame:view.bounds];
self.view.backgroundColor = [UIColor blackColor];
self.view.alpha = 0.3;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
[view addSubview:self.view];
self.view.hidden = YES;
self.mySuperView = view;
[self creatCommentTextField];
self.isReply = NO;
// NSString *chContent = [NSString stringWithFormat:UMComLocalizedString(@"um_com_commentLimit_template", @"评论内容不能超过%d个字符"),(int)self.maxTextLenght];
NSString *chContent = [NSString stringWithFormat:UMComLocalizedString(@"um_com_input_content", @"输入内容"),(int)self.maxTextLenght];
self.commentTextField.placeholder = chContent;
}
return self;
}
- (void)creatCommentTextField
{
NSArray *commentInputNibs = [[NSBundle mainBundle]loadNibNamed:@"UMComSimpleCommentInput" owner:self options:nil];
self.maxTextLenght = [UMComSession sharedInstance].comment_length;
//得到第一个UIView
UIView *commentInputView = [commentInputNibs objectAtIndex:0];
self.commentInputView = commentInputView;
// [self.commentInputView addSubview:[self creatSpaceLineWithWidth:self.mySuperView.frame.size.width]];
self.commentTextField = [commentInputView.subviews objectAtIndex:0];
self.favoriteButton = [commentInputView.subviews objectAtIndex:1];
self.likeButton = [commentInputView.subviews objectAtIndex:2];
self.sendButton = [commentInputView.subviews objectAtIndex:3];
self.sendButton.hidden = YES;
self.sendButton.backgroundColor = UMComColorWithHexString(@"#469ef8");
self.sendButton.layer.cornerRadius = self.sendButton.frame.size.height/2;
self.sendButton.clipsToBounds = YES;
[self.sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.commentTextField.delegate = self;
self.commentTextField.delegate = self;
self.commentInputView.frame = CGRectMake(0, self.view.frame.size.height-self.commentInputView.frame.size.height, self.view.frame.size.width, self.commentInputView.frame.size.height);
[self.mySuperView addSubview:self.commentInputView];
[self.mySuperView bringSubviewToFront:self.commentInputView];
[self.favoriteButton addTarget:self action:@selector(clickOnFavorite) forControlEvents:UIControlEventTouchUpInside];
[self.likeButton addTarget:self action:@selector(clickOnLike) forControlEvents:UIControlEventTouchUpInside];
[self.sendButton addTarget:self action:@selector(sendCommend) forControlEvents:UIControlEventTouchUpInside];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
[self.commentTextField addTarget:self action:@selector(onChangeTextField) forControlEvents:UIControlEventEditingChanged];
}
- (void)sendCommend
{
if (self.commentTextField.text.length > self.maxTextLenght) {
[UMComShowToast commentMoreWord];
return;
}
if (self.SendCommentHandler) {
self.SendCommentHandler(self.commentTextField.text);
}
self.commentTextField.text = @"";
self.commentTextField.placeholder = @"";
[self dismissKeyboard];
}
- (void)clickOnFavorite
{
if (self.clickOnFavoriteButtonBlock) {
self.clickOnFavoriteButtonBlock(self.favoriteButton);
}
}
- (void)clickOnLike
{
if (self.clickOnLikeButtonBlock) {
self.clickOnLikeButtonBlock(self.likeButton);
}
}
- (UIView *)creatSpaceLineWithWidth:(CGFloat)width
{
UIView *spaceLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 0.5)];
spaceLine.backgroundColor = UMComTableViewSeparatorColor;
spaceLine.autoresizingMask = UIViewAutoresizingFlexibleWidth;
return spaceLine;
}
-(void)presentEditView
{
self.commentTextField.text = @"";
if (self.commentTextField.placeholder.length == 0) {
NSString *chContent = [NSString stringWithFormat:UMComLocalizedString(@"um_com_input_content", @"输入内容"),(int)self.maxTextLenght];
self.commentTextField.placeholder = chContent;
}
self.commentTextField.hidden = NO;
self.commentInputView.hidden = NO;
self.view.hidden = NO;
[self.commentTextField becomeFirstResponder];
}
- (void)dismissKeyboard
{
self.view.hidden = YES;
if ([self.commentTextField becomeFirstResponder]) {
[self.commentTextField resignFirstResponder];
}
NSString *chContent = [NSString stringWithFormat:UMComLocalizedString(@"um_com_input_content", @"输入内容"),(int)self.maxTextLenght];
self.commentTextField.placeholder = chContent;
self.commentTextField.text = @"";
}
- (void)addAllEditView
{
if (self.view.superview != self.mySuperView) {
[self.mySuperView addSubview:self.view];
[self.mySuperView addSubview:self.commentInputView];
}
}
- (void)removeAllEditView
{
[self.commentInputView removeFromSuperview];
[self.view removeFromSuperview];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
{
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField.text.length >= self.maxTextLenght && [string isEqualToString:@""]) {
textField.text = [textField.text substringToIndex:textField.text.length-1];
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (self.commentTextField.text.length > self.maxTextLenght) {
[UMComShowToast commentMoreWord];
return NO;
}
if (self.SendCommentHandler) {
self.SendCommentHandler(textField.text);
}
[self dismissKeyboard];
return YES;
}
- (void)onChangeTextField
{
NSInteger textLenght = self.commentTextField.text.length;
if (textLenght > self.maxTextLenght) {
[UMComShowToast commentMoreWord];
NSString *sunString = [self.commentTextField.text substringWithRange:NSMakeRange(0, self.maxTextLenght)];
self.commentTextField.text = sunString;
return;
}
self.lastText = self.commentTextField.text;
}
- (void)hidenNoticeLabel
{
self.noticeLabel.hidden = YES;
self.commentTextField.hidden = NO;
}
- (void)keyboardWillShow:(NSNotification*)notification {
[self.mySuperView bringSubviewToFront:self.commentInputView];
self.view.hidden = NO;
self.sendButton.hidden = NO;
self.favoriteButton.hidden = YES;
self.likeButton.hidden = YES;
// get keyboard size and loctaion
CGRect keyboardBounds;
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
// Need to translate the bounds to account for rotation.
keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
// get a rect for the textView frame
CGRect commentInputViewFrame = self.commentInputView.frame;
commentInputViewFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + commentInputViewFrame.size.height);
// animations settings
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
// set views with new info
self.commentInputView.frame = commentInputViewFrame;
for (NSLayoutConstraint *constraint in self.commentInputView.constraints) {
if (constraint.firstItem == self.sendButton && constraint.secondItem == self.commentTextField && constraint.firstAttribute == NSLayoutAttributeLeading && constraint.secondAttribute == NSLayoutAttributeTrailing) {
constraint.priority = 900;
}
if (constraint.firstItem == self.favoriteButton && constraint.secondItem == self.commentTextField && constraint.firstAttribute == NSLayoutAttributeLeading && constraint.secondAttribute == NSLayoutAttributeTrailing) {
constraint.priority = 750;
}
}
// [self.commentInputView updateConstraintsIfNeeded];
[UIView commitAnimations];
}
- (void) keyboardWillHide:(NSNotification *)note
{
self.sendButton.hidden = YES;
self.favoriteButton.hidden = NO;
self.likeButton.hidden = NO;
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
// get a rect for the textView frame
CGRect commentInputViewFrame = self.commentInputView.frame;
commentInputViewFrame.origin.y = self.view.bounds.size.height - commentInputViewFrame.size.height;
// animations settings
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
self.view.hidden = YES;
// set views with new info
self.commentInputView.frame = commentInputViewFrame;
for (NSLayoutConstraint *constraint in self.commentInputView.constraints) {
if (constraint.firstItem == self.sendButton && constraint.secondItem == self.commentTextField && constraint.firstAttribute == NSLayoutAttributeLeading && constraint.secondAttribute == NSLayoutAttributeTrailing) {
constraint.priority = 750;
}
if (constraint.firstItem == self.favoriteButton && constraint.secondItem == self.commentTextField && constraint.firstAttribute == NSLayoutAttributeLeading && constraint.secondAttribute == NSLayoutAttributeTrailing) {
constraint.priority = 900;
}
}
// [self.commentInputView updateConstraintsIfNeeded];
[UIView commitAnimations];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.commentInputView = nil;
self.view = nil;
self.mySuperView = nil;
self.commentTextField = nil;
self.noticeLabel = nil;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="emQ-SZ-HSs">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="qaO-4s-dt4" userLabel="commentField">
<rect key="frame" x="10" y="11" width="224" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="cFP-7b-og1"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="send"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cX4-pX-Vne" userLabel="favoriteButton">
<rect key="frame" x="244" y="11" width="28" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="ASC-Kb-dG7"/>
<constraint firstAttribute="width" constant="28" id="k5F-Dt-ATB"/>
</constraints>
<state key="normal" image="UMComSimpleSDKResources.bundle/images/um_favorite_circle_nomal"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mDW-TK-jD7" userLabel="likeButton">
<rect key="frame" x="282" y="11" width="28" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="NCH-IX-EVW"/>
<constraint firstAttribute="width" constant="28" id="i44-HX-FhD"/>
</constraints>
<state key="normal" image="UMComSimpleSDKResources.bundle/images/um_like_circle_highlight">
<color key="titleColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1vM-Cn-SiK" userLabel="sendButton">
<rect key="frame" x="256" y="11" width="54" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="Qqt-rO-Jof"/>
<constraint firstAttribute="width" constant="54" id="Zwl-9K-CWa"/>
</constraints>
<state key="normal" title="发送"/>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="x6F-45-tKH" userLabel="topLine">
<rect key="frame" x="0.0" y="-1" width="320" height="1"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="6YE-9l-PUp"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1dm-5h-Lfb" userLabel="bottomLine">
<rect key="frame" x="0.0" y="50" width="282" height="1"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="6Rp-EI-2IE"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="qaO-4s-dt4" firstAttribute="leading" secondItem="emQ-SZ-HSs" secondAttribute="leading" constant="10" id="6Y0-BR-tF5"/>
<constraint firstAttribute="trailing" secondItem="mDW-TK-jD7" secondAttribute="trailing" constant="10" id="9qz-BN-gkc"/>
<constraint firstAttribute="trailing" secondItem="1vM-Cn-SiK" secondAttribute="trailing" constant="10" id="AR0-0P-ULq"/>
<constraint firstAttribute="bottom" secondItem="mDW-TK-jD7" secondAttribute="bottom" constant="11" id="Bar-un-OHm"/>
<constraint firstItem="1dm-5h-Lfb" firstAttribute="top" secondItem="1vM-Cn-SiK" secondAttribute="bottom" constant="11" id="E8O-WL-ZvG"/>
<constraint firstItem="x6F-45-tKH" firstAttribute="top" secondItem="emQ-SZ-HSs" secondAttribute="top" constant="-1" id="HMO-uI-eUj"/>
<constraint firstItem="cX4-pX-Vne" firstAttribute="leading" secondItem="qaO-4s-dt4" secondAttribute="trailing" priority="750" constant="10" id="Hv9-kq-Edg"/>
<constraint firstItem="cX4-pX-Vne" firstAttribute="top" secondItem="emQ-SZ-HSs" secondAttribute="top" constant="11" id="J6J-PI-G90"/>
<constraint firstItem="1dm-5h-Lfb" firstAttribute="leading" secondItem="emQ-SZ-HSs" secondAttribute="leading" id="KJU-ar-ehp"/>
<constraint firstItem="x6F-45-tKH" firstAttribute="leading" secondItem="emQ-SZ-HSs" secondAttribute="leading" id="KwH-bL-V9M"/>
<constraint firstAttribute="trailing" secondItem="x6F-45-tKH" secondAttribute="trailing" id="LBF-Bf-0UG"/>
<constraint firstAttribute="bottom" secondItem="1dm-5h-Lfb" secondAttribute="bottom" constant="-1" id="NTX-D1-58p"/>
<constraint firstAttribute="bottom" secondItem="cX4-pX-Vne" secondAttribute="bottom" constant="11" id="RiF-ix-Qce"/>
<constraint firstItem="mDW-TK-jD7" firstAttribute="top" secondItem="emQ-SZ-HSs" secondAttribute="top" constant="11" id="dlw-FK-aA2"/>
<constraint firstItem="mDW-TK-jD7" firstAttribute="leading" secondItem="1dm-5h-Lfb" secondAttribute="trailing" id="jJM-h5-LlZ"/>
<constraint firstItem="qaO-4s-dt4" firstAttribute="top" secondItem="emQ-SZ-HSs" secondAttribute="top" constant="11" id="m9R-eJ-y36"/>
<constraint firstAttribute="bottom" secondItem="qaO-4s-dt4" secondAttribute="bottom" constant="11" id="mQh-5D-C3j"/>
<constraint firstItem="1vM-Cn-SiK" firstAttribute="top" secondItem="x6F-45-tKH" secondAttribute="bottom" constant="11" id="pEq-6r-PLT"/>
<constraint firstItem="1vM-Cn-SiK" firstAttribute="leading" secondItem="qaO-4s-dt4" secondAttribute="trailing" priority="750" constant="10" id="qtx-Xd-sPx"/>
<constraint firstItem="mDW-TK-jD7" firstAttribute="leading" secondItem="cX4-pX-Vne" secondAttribute="trailing" constant="10" id="vez-9Y-DDr"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="149" y="-20.5"/>
</view>
</objects>
<resources>
<image name="UMComSimpleSDKResources.bundle/images/um_favorite_circle_nomal" width="75" height="75"/>
<image name="UMComSimpleSDKResources.bundle/images/um_like_circle_highlight" width="75" height="75"/>
</resources>
</document>