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,43 @@
//
// UMComPostReplyEditView.h
// UMCommunity
//
// Created by umeng on 12/10/15.
// Copyright © 2015 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, UMComPostReplyImagePickerType)
{
UMComPostReplyImagePickerLibrary,
UMComPostReplyImagePickerCamera
};
typedef void (^UMComPostReplyCommitBlock)(NSString *content, NSArray *imageList);
typedef void (^UMComPostReplyCancelBlock)();
typedef void (^UMComPostReplyCommitGetImageBlock)(UMComPostReplyImagePickerType type);
@interface UMComPostReplyEditView : UIView
<UITextViewDelegate>
@property (nonatomic, weak) IBOutlet UITextView *textView;
@property (nonatomic, weak) IBOutlet UIView *contentView;
@property (nonatomic, weak) IBOutlet UILabel *textCountMarker;
@property (nonatomic, weak) IBOutlet UIButton *addImageButton;
@property (nonatomic, weak) IBOutlet UIButton *commitButton;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *contentBottomConstraints;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *contentHeightConstraints;
@property (nonatomic, strong) UMComPostReplyCommitGetImageBlock getImageBlock;
- (IBAction)commit:(id)sender;
- (IBAction)cancel:(id)sender;
- (IBAction)addImage:(id)sender;
- (void)displayWithMaxLength:(NSUInteger)length commitBlock:(UMComPostReplyCommitBlock)commitBlock cancelBlock:(UMComPostReplyCancelBlock)cancelBlock;
- (void)addPickedImage:(UIImage *)image;
- (void)setImageAssets:(NSArray *)imageAssets;
@end
@@ -0,0 +1,237 @@
//
// UMComPostReplyEditView.m
// UMCommunity
//
// Created by umeng on 12/10/15.
// Copyright © 2015 Umeng. All rights reserved.
//
#import "UMComPostReplyEditView.h"
#import "UMComiToast.h"
#import "UMComResouceDefines.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <UMComFoundation/UMComKit+String.h>
#import <UMComFoundation/UMComKit+Color.h>
#define UMComReplyThumbImageKey @"UMComReplyThumbImageKey"
#define UMComReplyImageKey @"UMComReplyImageKey"
@interface UMComPostReplyEditView()
<UIActionSheetDelegate>
@property (nonatomic, assign) NSUInteger maxLength;
@property (nonatomic, strong) UMComPostReplyCommitBlock commitBlock;
@property (nonatomic, strong) UMComPostReplyCancelBlock cancelBlock;
@property (nonatomic, strong) NSMutableArray *pickedImageList;
@end
@implementation UMComPostReplyEditView
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)displayWithMaxLength:(NSUInteger)length commitBlock:(UMComPostReplyCommitBlock)commitBlock cancelBlock:(UMComPostReplyCancelBlock)cancelBlock
{
self.maxLength = length;
self.commitBlock = commitBlock;
self.cancelBlock = cancelBlock;
[self initViews];
[self registerKeyboard];
[_textView becomeFirstResponder];
}
- (void)registerKeyboard
{
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(showKeyboard:)
// name:UIKeyboardDidShowNotification
// object:nil];
}
- (void)initViews
{
__weak typeof(self) ws = self;
_textCountMarker.text = [NSString stringWithFormat:@"0/%lu", _maxLength];
self.pickedImageList = [NSMutableArray array];
}
- (IBAction)cancel:(id)sender;
{
[self removeFromSuperview];
if (_cancelBlock) {
_cancelBlock();
}
}
- (IBAction)commit:(id)sender
{
if (_textView.text.length == 0 && _pickedImageList.count == 0) {
[[UMComiToast makeText:UMComLocalizedString(@"um_com_empty_relpyContent", @"回复内容不能为空")] show];
return;
}
if ([UMComKit getStringLengthWithString:_textView.text] > _maxLength) {
[[UMComiToast makeText:[NSString stringWithFormat:UMComLocalizedString(@"um_com_relpyContent_maxnumber_template", @"回复长度最多为%lu"), _maxLength]] show];
return;
}
if (_commitBlock) {
NSArray *imageList = nil;
if (_pickedImageList.count > 0) {
imageList = @[_pickedImageList[0][UMComReplyImageKey]];
}
_commitBlock(_textView.text, imageList);
}
[self removeFromSuperview];
}
- (IBAction)addImage:(id)sender
{
[self popActionSheetForAddImageView];
}
-(void) popActionSheetForAddImageView
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:UMComLocalizedString(@"um_com_selectImageSource",@"请选择图片源:")
delegate:self
cancelButtonTitle:UMComLocalizedString(@"um_com_cancel", @"取消")
destructiveButtonTitle:nil
otherButtonTitles:UMComLocalizedString(@"um_com_camera",@"拍照"),UMComLocalizedString(@"um_com_album", @"相册"),nil];
[_textView resignFirstResponder];
[sheet showInView:self];
}
- (void)textViewDidChange:(UITextView *)textView
{
_textCountMarker.text = [NSString stringWithFormat:@"%lu/%lu", [UMComKit getStringLengthWithString:_textView.text], _maxLength];
_commitButton.selected = _textView.text.length > 0;
if ([UMComKit getStringLengthWithString:_textView.text] > _maxLength) {
_textCountMarker.textColor = [UIColor redColor];
} else {
_textCountMarker.textColor = UMComColorWithHexString(@"#A5A5A5");
}
}
- (void)showKeyboard:(NSNotification *)note
{
NSDictionary* info = [note userInfo];
CGSize size = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// if(kbSize.height == 216)
// {
// keyboardhight = 0;
// }
// else
// {
// keyboardhight = 36; //252 - 216 键盘的两个高度
// }
[self textViewMoveAnimation:size.height];
}
- (void)textViewMoveAnimation:(NSUInteger)height
{
CGRect frame = _contentView.frame;
if (frame.origin.y < self.frame.size.height - frame.size.height - height) {
return;
}
[UIView animateWithDuration:0.5f
animations:^{
CGRect frame = _contentView.frame;
frame.origin.y = self.frame.size.height - frame.size.height - height;
_contentView.frame = frame;
}
completion:^(BOOL finished) {
}];
}
- (void)addDeleteButton
{
CGSize delSize = CGSizeMake(18.f, 18.f);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[_contentView addSubview:button];
button.frame = CGRectMake(_addImageButton.frame.origin.x + _addImageButton.frame.size.width - delSize.width, _addImageButton.frame.origin.y - delSize.height, delSize.width, delSize.height);
[button setImage:UMComImageWithImageName(@"um_forum_delete_gray") forState:UIControlStateNormal];
[button addTarget:self action:@selector (deleteImage:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)deleteImage:(id)sender
{
UIButton *delButton = (UIButton *)sender;
[delButton removeFromSuperview];
[_addImageButton setImage:UMComImageWithImageName(@"um_forum_add_image_gray") forState:UIControlStateNormal];
_addImageButton.userInteractionEnabled = YES;
[_pickedImageList removeAllObjects];
}
- (void)addPickedImage:(UIImage *)image
{
if (!image) {
return;
}
[_pickedImageList addObject:@{UMComReplyThumbImageKey:image, UMComReplyImageKey: image}];
[self setImage:image];
}
- (void)setImageAssets:(NSArray *)imageAssets
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
for(ALAsset *asset in imageAssets)
{
UIImage *thumbImage = [UIImage imageWithCGImage:[asset thumbnail]];
UIImage *originImage = [UIImage
imageWithCGImage:[asset.defaultRepresentation fullScreenImage]
scale:[asset.defaultRepresentation scale]
orientation:UIImageOrientationUp];
NSData *originData = UIImageJPEGRepresentation(originImage, .9f);
[_pickedImageList addObject:@{UMComReplyThumbImageKey: thumbImage, UMComReplyImageKey: [UIImage imageWithData:originData]}];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self setImage:_pickedImageList[0][UMComReplyImageKey]];
});
});
}
- (void)setImage:(UIImage *)image
{
_addImageButton.userInteractionEnabled = NO;
[_addImageButton setImage:image forState:UIControlStateNormal];
[self addDeleteButton];
}
#pragma mark - Delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
if (_getImageBlock) {
_getImageBlock(UMComPostReplyImagePickerCamera);
}
break;
case 1:
if (_getImageBlock) {
_getImageBlock(UMComPostReplyImagePickerLibrary);
}
break;
case 2:
[_textView becomeFirstResponder];
break;
default:
break;
}
}
@end
@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<development version="6000" identifier="xcode"/>
<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 autoresizesSubviews="NO" contentMode="scaleToFill" id="iN0-l3-epB" customClass="UMComPostReplyEditView">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view alpha="0.69999999999999996" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Dl9-NB-1CQ" userLabel="maskView">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1Dv-pq-6GK">
<rect key="frame" x="0.0" y="268" width="320" height="300"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ibC-Od-UhJ" userLabel="top">
<rect key="frame" x="0.0" y="0.0" width="320" height="42"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QLS-vZ-IOA">
<rect key="frame" x="10" y="5" width="40" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="51f-gZ-WRB"/>
<constraint firstAttribute="width" constant="40" id="gIh-ZJ-JRM"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="取消">
<color key="titleColor" red="0.6470588235294118" green="0.6470588235294118" blue="0.6470588235294118" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="cancel:" destination="iN0-l3-epB" eventType="touchUpInside" id="Eed-HP-Gvn"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wFy-cs-mRY">
<rect key="frame" x="270" y="5" width="40" height="28"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="lNI-dx-3uN"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="28" id="mAG-DA-RIh"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="提交">
<color key="titleColor" red="0.88235294117647056" green="0.88235294117647056" blue="0.88235294117647056" alpha="1" colorSpace="calibratedRGB"/>
</state>
<state key="selected">
<color key="titleColor" red="0.0" green="0.54509803921568623" blue="0.91764705882352937" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="commit:" destination="iN0-l3-epB" eventType="touchUpInside" id="WqT-Ys-r15"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.96078431372549022" green="0.96470588235294119" blue="0.98039215686274506" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="wFy-cs-mRY" firstAttribute="height" secondItem="QLS-vZ-IOA" secondAttribute="height" id="Dgp-jU-Rst"/>
<constraint firstAttribute="trailing" secondItem="wFy-cs-mRY" secondAttribute="trailing" constant="10" id="IHn-iQ-00l"/>
<constraint firstItem="QLS-vZ-IOA" firstAttribute="top" secondItem="ibC-Od-UhJ" secondAttribute="top" constant="5" id="Mfn-hN-3h8"/>
<constraint firstAttribute="height" constant="42" id="fBO-oC-lMu"/>
<constraint firstItem="wFy-cs-mRY" firstAttribute="top" secondItem="ibC-Od-UhJ" secondAttribute="top" constant="5" id="tuZ-8A-XFx"/>
<constraint firstItem="QLS-vZ-IOA" firstAttribute="leading" secondItem="ibC-Od-UhJ" secondAttribute="leading" constant="10" id="uo4-Xi-6Ui"/>
</constraints>
<edgeInsets key="layoutMargins" top="0.0" left="0.0" bottom="8" right="0.0"/>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="JvX-eh-Owp">
<rect key="frame" x="5" y="42" width="310" height="162"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<connections>
<outlet property="delegate" destination="iN0-l3-epB" id="1nU-qE-2jP"/>
</connections>
</textView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0/most" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eVe-EC-OGM">
<rect key="frame" x="259" y="268" width="46" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.6470588235294118" green="0.6470588235294118" blue="0.6470588235294118" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="z6r-ml-bT2">
<rect key="frame" x="15" y="202" width="83" height="83"/>
<constraints>
<constraint firstAttribute="height" constant="83" id="0uJ-8f-Uy5"/>
<constraint firstAttribute="width" constant="83" id="F8C-YV-BFK"/>
</constraints>
<state key="normal" title="Button" image="UMComSDKResources.bundle/images/um_forum_add_image_gray.png"/>
<connections>
<action selector="addImage:" destination="iN0-l3-epB" eventType="touchUpInside" id="361-ex-RcS"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="ibC-Od-UhJ" firstAttribute="top" secondItem="1Dv-pq-6GK" secondAttribute="top" id="1xy-QK-CUq"/>
<constraint firstItem="z6r-ml-bT2" firstAttribute="top" secondItem="JvX-eh-Owp" secondAttribute="bottom" constant="-2" id="7j2-lW-mUV"/>
<constraint firstAttribute="trailing" secondItem="eVe-EC-OGM" secondAttribute="trailing" constant="15" id="H7I-Bi-CU5"/>
<constraint firstItem="JvX-eh-Owp" firstAttribute="top" secondItem="ibC-Od-UhJ" secondAttribute="bottom" id="KOV-IE-xJO"/>
<constraint firstItem="z6r-ml-bT2" firstAttribute="leading" secondItem="1Dv-pq-6GK" secondAttribute="leading" constant="15" id="W8s-iM-93Q"/>
<constraint firstAttribute="trailing" secondItem="JvX-eh-Owp" secondAttribute="trailing" constant="5" id="WOX-3a-hQX"/>
<constraint firstItem="ibC-Od-UhJ" firstAttribute="leading" secondItem="1Dv-pq-6GK" secondAttribute="leading" id="Wik-IU-HXy"/>
<constraint firstAttribute="trailing" secondItem="ibC-Od-UhJ" secondAttribute="trailing" id="dz8-vj-UwC"/>
<constraint firstAttribute="bottom" secondItem="z6r-ml-bT2" secondAttribute="bottom" constant="15" id="hwA-Hp-rBs"/>
<constraint firstItem="JvX-eh-Owp" firstAttribute="leading" secondItem="1Dv-pq-6GK" secondAttribute="leading" constant="5" id="jAL-B8-oOR"/>
<constraint firstAttribute="height" constant="300" id="ppu-oh-2Vw"/>
<constraint firstAttribute="bottom" secondItem="eVe-EC-OGM" secondAttribute="bottom" constant="15" id="qhU-Z1-qyz"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstItem="1Dv-pq-6GK" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="DKb-vc-ZAf"/>
<constraint firstAttribute="trailing" secondItem="1Dv-pq-6GK" secondAttribute="trailing" id="KtJ-UG-PdF"/>
<constraint firstAttribute="trailing" secondItem="Dl9-NB-1CQ" secondAttribute="trailing" id="Pjk-SM-pnx"/>
<constraint firstAttribute="bottom" secondItem="Dl9-NB-1CQ" secondAttribute="bottom" id="Qt5-6Q-kEa"/>
<constraint firstAttribute="bottom" secondItem="1Dv-pq-6GK" secondAttribute="bottom" id="Xnq-Z7-c4W"/>
<constraint firstItem="Dl9-NB-1CQ" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="bYx-Pf-TLH"/>
<constraint firstItem="Dl9-NB-1CQ" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="fDg-rE-YRe"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="addImageButton" destination="z6r-ml-bT2" id="qc1-NC-ecC"/>
<outlet property="commitButton" destination="wFy-cs-mRY" id="MYT-Y1-JTq"/>
<outlet property="contentBottomConstraints" destination="Xnq-Z7-c4W" id="TRX-M1-F39"/>
<outlet property="contentHeightConstraints" destination="ppu-oh-2Vw" id="MK4-a3-RJ2"/>
<outlet property="contentView" destination="1Dv-pq-6GK" id="pqt-Nf-LL8"/>
<outlet property="textCountMarker" destination="eVe-EC-OGM" id="JbP-tx-t8L"/>
<outlet property="textView" destination="JvX-eh-Owp" id="ptw-eA-zJT"/>
</connections>
<point key="canvasLocation" x="-46" y="365"/>
</view>
</objects>
<resources>
<image name="UMComSDKResources.bundle/images/um_forum_add_image_gray.png" width="75" height="75"/>
</resources>
</document>
@@ -0,0 +1,21 @@
//
// UMComReplyEditViewController.h
// UMCommunity
//
// Created by 张军华 on 16/2/3.
// Copyright © 2016年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComPostReplyEditView.h"
@interface UMComReplyEditViewController : UIViewController
@property(nonatomic,readwrite,copy)UMComPostReplyCommitBlock commitBlock;
@property(nonatomic,readwrite,copy)UMComPostReplyCancelBlock cancelBlock;
@property (nonatomic, readwrite,copy)UMComPostReplyCommitGetImageBlock getImageBlock;
//回复评论者的名字
@property(nonatomic,readwrite,strong)NSString* commentcreator;
@end
@@ -0,0 +1,442 @@
//
// UMComReplyEditViewController.m
// UMCommunity
//
// Created by 张军华 on 16/2/3.
// Copyright © 2016年 Umeng. All rights reserved.
//
#import "UMComReplyEditViewController.h"
#import <UMCommunitySDK/UMComSession.h>
#import "UMComEmojiKeyboardView.h"
#import "UMComResouceDefines.h"
#import "UMImagePickerController.h"
#import "UMComNavigationController.h"
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetsLibrary.h>
#import <AssetsLibrary/ALAssetsGroup.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
#import <UIKit/UIImagePickerController.h>
#import <UMComFoundation/UMComKit+Color.h>
#import <UMComFoundation/UMComDefines.h>
const CGFloat g_ReplyEditView_EditMenuViewViewHeight = 45.f;//表情框的高度
const CGFloat g_ReplyEditView_leftMargin = 15.f;//控件的左边距间距
@interface UMComReplyEditViewController ()<UMComEmojiKeyboardViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextViewDelegate>
//回复的编辑界面的view
@property(nonatomic,readwrite,strong)UMComPostReplyEditView* postReplyEditView;
@property(nonatomic,readwrite,strong)UITextView *textView;
@property(nonatomic,readwrite,strong)UILabel* placeholderLabel;
-(void)updateTextViewWord;
-(void)createImagePicker;
-(void)takePhoto;
@property (nonatomic, strong) UMComEmojiKeyboardView *emojiKeyboardView;
@property(nonatomic,readwrite,strong)UIView* menuView;//为标题控件对应
@property(nonatomic,strong)UIButton* emojiBtn;//点击表情的按钮
-(void)createPostReplyEditView;
-(void) createEmojiKeyboardView;
-(void) createMenuView;
-(void) showEmojiKeyboardViewWithTextView:(UITextView*)textview;
-(void) changeEmojiBtnImg:(BOOL)isEmoji withTextView:(UITextView*)textview;
-(void) appendEmoji:(NSString*)emoji withUITextView:(UITextView*)textview;
@end
@implementation UMComReplyEditViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
if (UMComSystem_Version_Greater_Than_Or_Equal_To(@"7.0")) {
[self setNeedsStatusBarAppearanceUpdate];
}
[self createPostReplyEditView];
[self.postReplyEditView displayWithMaxLength:[UMComSession sharedInstance].comment_length commitBlock:self.commitBlock cancelBlock:self.cancelBlock];
__weak typeof(self) weakself = self;
self.postReplyEditView.getImageBlock = ^(UMComPostReplyImagePickerType type){
if (type == UMComPostReplyImagePickerCamera) {
[weakself takePhoto];
} else if(type == UMComPostReplyImagePickerLibrary){
[weakself createImagePicker];
}
else{
[weakself.textView becomeFirstResponder];
}
};
//赋值给textView
self.textView = self.postReplyEditView.textView;
if (self.textView && self.commentcreator) {
NSString* tempCommentTip = [[NSString alloc] initWithFormat:UMComLocalizedString(@"um_com_replyCreator_template", @"回复 %@:"),self.commentcreator];
self.placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, -5,self.textView.bounds.size.width, 40)];
self.placeholderLabel.font = self.textView.font;
_placeholderLabel.backgroundColor = [UIColor clearColor];
_placeholderLabel.textColor = [UIColor grayColor];
_placeholderLabel.text = tempCommentTip;
[self.textView addSubview:_placeholderLabel];
}
self.textView.delegate = self;
[self createMenuView];
[self createEmojiKeyboardView];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)prefersStatusBarHidden
{
if (UMComSystem_Version_Greater_Than_Or_Equal_To(@"7.0")) {
return YES;
}
return NO;
}
#pragma mark - new method
-(void)createPostReplyEditView
{
NSArray *viewArray = [[NSBundle mainBundle] loadNibNamed:@"UMComPostReplyEditView" owner:self options:nil];
UMComPostReplyEditView *replyView = viewArray[0];
replyView.frame = self.view.bounds;
self.postReplyEditView = replyView;
[self.view addSubview:replyView];
}
-(void) createEmojiKeyboardView
{
if (!self.emojiKeyboardView) {
//添加表情控件
UMComEmojiKeyboardView *emojiKeyboardView = [[UMComEmojiKeyboardView alloc] initWithFrame:CGRectMake(0, 300, self.view.frame.size.width, 216) dataSource:nil];
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = self;
self.emojiKeyboardView = emojiKeyboardView;
}
}
-(void) createMenuView
{
self.menuView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, g_ReplyEditView_EditMenuViewViewHeight)];
self.menuView.backgroundColor = [UIColor whiteColor];
UIButton* emojiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
CGFloat emojiBtn_y = (g_ReplyEditView_EditMenuViewViewHeight -30)/2;
emojiBtn.frame = CGRectMake(g_ReplyEditView_leftMargin,emojiBtn_y,30,30);
[emojiBtn addTarget:self action:@selector(handleBtnChangeEmojiBtnImg:) forControlEvents:UIControlEventTouchUpInside];
//显示表情
[emojiBtn setBackgroundImage:UMComImageWithImageName(@"um_edit_emoji_normal") forState:UIControlStateNormal];
[emojiBtn setBackgroundImage:UMComImageWithImageName(@"um_edit_emoji_highlight") forState:UIControlStateHighlighted];
[self.menuView addSubview:emojiBtn];
self.emojiBtn = emojiBtn;
UIView* separateView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 1)];
separateView.backgroundColor = UMComColorWithHexString(@"eeeff3");
[self.menuView addSubview:separateView];
self.textView.inputAccessoryView = self.menuView;
}
-(void)updateTextViewWord
{
if (self.textView.text.length <= 0) {
self.placeholderLabel.hidden = NO;
}
else
{
self.placeholderLabel.hidden = YES;
}
if ([self.postReplyEditView respondsToSelector:@selector(textViewDidChange:)]){
[self.postReplyEditView textViewDidChange:self.textView];
}
}
-(void)handleBtnChangeEmojiBtnImg:(UIButton*)target
{
[self showEmojiKeyboardViewWithTextView:self.textView];
}
-(void) showEmojiKeyboardViewWithTextView:(UITextView*)textview
{
if (self.textView.inputView == nil) {
self.textView.inputView = self.emojiKeyboardView;
[self.textView resignFirstResponder];
[self.textView becomeFirstResponder];
[self changeEmojiBtnImg:NO withTextView:self.textView];
} else {
self.textView.inputView = nil;
[self.textView resignFirstResponder];
[self.textView becomeFirstResponder];
[self changeEmojiBtnImg:YES withTextView:self.textView];
}
}
-(void) changeEmojiBtnImg:(BOOL)isEmoji withTextView:(UITextView*)textview
{
if (textview == self.textView)
{
if (isEmoji) {
//显示表情
[self.emojiBtn setBackgroundImage:UMComImageWithImageName(@"um_edit_emoji_normal") forState:UIControlStateNormal];
[self.emojiBtn setBackgroundImage:UMComImageWithImageName(@"um_edit_emoji_highlight") forState:UIControlStateHighlighted];
}
else
{
//显示键盘
[self.emojiBtn setBackgroundImage:UMComImageWithImageName(@"um_edit_keyboard_normal") forState:UIControlStateNormal];
[self.emojiBtn setBackgroundImage:UMComImageWithImageName(@"um_edit_keyboard_highlight") forState:UIControlStateHighlighted];
}
}
}
#pragma mark - UMComEmojiKeyboardViewDelegate
/**
Delegate method called when user taps an emoji button
@param emojiKeyBoardView EmojiKeyBoardView object on which user has tapped.
@param emoji Emoji used by user
*/
- (void)emojiKeyBoardView:(UMComEmojiKeyboardView *)emojiKeyBoardView
didUseEmoji:(NSString *)emoji
{
[self appendEmoji:emoji withUITextView:self.textView];
[self updateTextViewWord];
}
-(void) appendEmoji:(NSString*)emoji withUITextView:(UITextView*)textview
{
if (!emoji || !textview) {
return;
}
NSRange orgRange = textview.selectedRange;
NSRange rangeBefore;
rangeBefore.location = 0;
rangeBefore.length = orgRange.location;
NSString* orgBefore = [textview.text substringWithRange:[textview.text rangeOfComposedCharacterSequencesForRange:rangeBefore]];
NSRange rangeAfter;
rangeAfter.location = rangeBefore.location + rangeBefore.length;
if (orgBefore) {
//直接
rangeAfter.length = textview.text.length - orgBefore.length;
}
else
{
//如果用rangeBefore.length操作,可能会有问题
rangeAfter.length = textview.text.length - rangeBefore.length;
}
NSString* orgAfter = [textview.text substringWithRange:[textview.text rangeOfComposedCharacterSequencesForRange:rangeAfter]];
NSUInteger resultLocation = 0;
NSMutableString* resultString = [[NSMutableString alloc] initWithCapacity:10];
if (orgBefore) {
[resultString appendString:orgBefore];
resultLocation += orgBefore.length;
}
if (emoji) {
[resultString appendString:emoji];
resultLocation += emoji.length;
}
if (orgAfter) {
[resultString appendString:orgAfter];
}
textview.text = resultString;
textview.selectedRange = NSMakeRange(resultLocation, 0);
}
/**
Delegate method called when user taps on the backspace button
@param emojiKeyBoardView EmojiKeyBoardView object on which user has tapped.
*/
- (void)emojiKeyBoardViewDidPressBackSpace:(UMComEmojiKeyboardView *)emojiKeyBoardView
{
[self.textView deleteBackward];
[self updateTextViewWord];
}
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *selectImage = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
UIImage *tempImage = nil;
if (selectImage.imageOrientation != UIImageOrientationUp) {
UIGraphicsBeginImageContext(selectImage.size);
[selectImage drawInRect:CGRectMake(0, 0, selectImage.size.width, selectImage.size.height)];
tempImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}else{
tempImage = selectImage;
}
[self.postReplyEditView addPickedImage:tempImage];
}
-(void)takePhoto
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted)
{
[[[UIAlertView alloc] initWithTitle:nil message:@"本应用无访问相机的权限,如需访问,可在设置中修改" delegate:nil cancelButtonTitle:UMComLocalizedString(@"um_com_ok", @"好的") otherButtonTitles:nil, nil] show];
return;
}
}else{
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusDenied || author == ALAuthorizationStatusRestricted)
{
[[[UIAlertView alloc] initWithTitle:nil message:@"本应用无访问相机的权限,如需访问,可在设置中修改" delegate:nil cancelButtonTitle:UMComLocalizedString(@"um_com_ok", @"好的") otherButtonTitles:nil, nil] show];
return;
}
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
__weak typeof(self) weakself = self;
[self presentViewController:imagePicker animated:YES completion:^{
[weakself.textView becomeFirstResponder];
}];
}
}
- (void)createImagePicker
{
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied)
{
[[[UIAlertView alloc] initWithTitle:nil message:UMComLocalizedString(@"um_com_photoAlbumAuthentication", @"本应用无访问照片的权限,如需访问,可在设置中修改") delegate:nil cancelButtonTitle:UMComLocalizedString(@"um_com_ok", @"好的") otherButtonTitles:nil, nil] show];
return;
}
if([UMImagePickerController isAccessible])
{
UMImagePickerController *imagePickerController = [[UMImagePickerController alloc] init];
imagePickerController.minimumNumberOfSelection = 1;
imagePickerController.maximumNumberOfSelection = 1;
__weak typeof(self) ws = self;
[imagePickerController setFinishHandle:^(BOOL isCanceled,NSArray *assets){
if(!isCanceled)
{
[ws.postReplyEditView setImageAssets:assets];
}
}];
UMComNavigationController *navigationController = [[UMComNavigationController alloc] initWithRootViewController:imagePickerController];
__weak typeof(self) weakself = self;
[self presentViewController:navigationController animated:YES completion:^{
[weakself.textView becomeFirstResponder];
}];
}
}
#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
// NSLog(@"UMComReplyEditViewController...textViewDidChange");
[self updateTextViewWord];
}
#pragma mark - 键盘监听事件
-(void)keyboardWillShow:(NSNotification*)notification
{
CGRect keybordFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
__weak typeof(self) ws = self;
[UIView animateWithDuration:.3f animations:^{
// adapting for short device
ws.postReplyEditView.contentHeightConstraints.constant = self.view.frame.size.height - keybordFrame.size.height;
// if (ws.postReplyEditView.contentHeightConstraints.constant == 300) {
// CGFloat offset = ws.postReplyEditView.contentView.frame.origin.y - keybordFrame.size.height;
// if (offset < 0) {
// if (ws.postReplyEditView.contentHeightConstraints.constant + offset < 0) {
// ws.postReplyEditView.contentHeightConstraints.constant = 0;
// } else {
// ws.postReplyEditView.contentHeightConstraints.constant += offset;
// }
// }
// }
ws.postReplyEditView.contentBottomConstraints.constant = keybordFrame.size.height;
[ws.postReplyEditView.contentView layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}
-(void)keyboardDidShow:(NSNotification*)notification
{
}
-(void)keyboardWillHide:(NSNotification*)notification
{
}
-(void)keyboardDidHide:(NSNotification*)notification
{
CGRect keybordFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
float endheight = keybordFrame.size.height;
CGRect tempEditViewFrame = self.postReplyEditView.contentView.frame;
CGRect tempViewFrame = self.view.frame;
CGFloat orgY = tempViewFrame.size.height - endheight - tempEditViewFrame.size.height;
tempEditViewFrame.origin.y = orgY;
self.postReplyEditView.contentView.frame = tempEditViewFrame;
}
@end