Initial commit
This commit is contained in:
+46
@@ -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
|
||||
+305
@@ -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
|
||||
+96
@@ -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>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// UMComGridView.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by luyiyuan on 14/8/27.
|
||||
// Copyright (c) 2014年 luyiyuan. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UMComSimpleGridViewerController.h"
|
||||
@interface UMComSimpleGridView : UIView
|
||||
|
||||
@property (nonatomic, strong) void (^TapInImage)(UMComSimpleGridViewerController *viewerViewController, UIImageView *imageView);
|
||||
|
||||
@property (nonatomic, assign) CGFloat totalWidth;
|
||||
|
||||
- (id)initWithArray:(NSArray *)array placeholder:(UIImage *)placeholder cellPad:(NSUInteger)cellPad;
|
||||
|
||||
- (void)setImages:(NSArray *)images placeholder:(UIImage *)placeholder cellPad:(NSInteger)cellPad;
|
||||
|
||||
- (void)setArray:(NSArray *)array;
|
||||
|
||||
- (void)setPresentFatherViewController:(UIViewController *)viewController;
|
||||
|
||||
//默认一周(60*60*24*7)
|
||||
- (void)setCacheSecondes:(NSTimeInterval)secondes;
|
||||
|
||||
- (void)startDownload;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
//
|
||||
// UMComGridView.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by luyiyuan on 14/8/27.
|
||||
// Copyright (c) 2014年 luyiyuan. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComSimpleGridView.h"
|
||||
#import "UMComImageView.h"
|
||||
#import "math.h"
|
||||
#import "UMComShowToast.h"
|
||||
#import <UMComFoundation/UMUtils.h>
|
||||
#import <UMComDataStorage/UMComImageUrl.h>
|
||||
#define HTTP_PREFIX @"http://"
|
||||
#define IMAGE_CELL_WIDTH 75
|
||||
#define A_WEEK_SECONDES (60*60*24*7)
|
||||
|
||||
|
||||
static inline CGRect getImageViewRect(NSUInteger index,NSInteger deltaWidth, NSUInteger cellPad)
|
||||
{
|
||||
CGFloat originX = 0;
|
||||
if (index%3 != 0) {
|
||||
originX = (cellPad+deltaWidth)*(index%3);
|
||||
}
|
||||
return CGRectMake(originX, (cellPad+deltaWidth)*(index/3), deltaWidth, deltaWidth);
|
||||
}
|
||||
|
||||
static inline CGSize getGridViewSize(NSArray *array,NSUInteger cellPad,CGFloat imageWidth)
|
||||
{
|
||||
CGSize size;
|
||||
|
||||
size.width = [array count]/3 > 0 ? (cellPad+imageWidth) * 3 + cellPad : (cellPad+imageWidth)*([array count]%3)+cellPad;
|
||||
|
||||
size.height = (cellPad+imageWidth)*(([array count] - 1)/3 + 1) + cellPad;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@interface UMComSimpleGridView ()
|
||||
|
||||
@property (nonatomic) NSUInteger cellPad;
|
||||
@property (nonatomic,strong) UIImage *placeholder;
|
||||
@property (nonatomic,strong) NSArray *imageModels;
|
||||
@property (nonatomic,strong) NSMutableArray *arrayImageView;
|
||||
@property (nonatomic,strong) UMComSimpleGridViewerController *viewerController;
|
||||
@property (nonatomic,strong) UIViewController *fatherController;
|
||||
|
||||
@property (nonatomic,assign) float imageDeltaWidth;
|
||||
|
||||
@end
|
||||
|
||||
@implementation UMComSimpleGridView
|
||||
|
||||
/*
|
||||
array 样例:
|
||||
|
||||
@[@[@"http://1",@"http://2"],@[],@[]]
|
||||
|
||||
*/
|
||||
|
||||
- (id)initWithArray:(NSArray *)array placeholder:(UIImage *)placeholder cellPad:(NSUInteger)cellPad
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if(self)
|
||||
{
|
||||
self.arrayImageView = [[NSMutableArray alloc] init];
|
||||
self.cellPad = cellPad;
|
||||
|
||||
self.placeholder = placeholder;
|
||||
|
||||
for(int i = 0; i<9; i++)
|
||||
{
|
||||
UMComImageView *iv = [[UMComImageView alloc] initWithPlaceholderImage:placeholder];
|
||||
|
||||
[iv setIsAutoStart:NO];
|
||||
|
||||
iv.tag = i + 100;
|
||||
|
||||
[iv setCacheSecondes:A_WEEK_SECONDES];
|
||||
|
||||
iv.userInteractionEnabled = YES;
|
||||
|
||||
[self.arrayImageView addObject:iv];
|
||||
}
|
||||
|
||||
[self setArray:array];
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setImages:(NSArray *)images placeholder:(UIImage *)placeholder cellPad:(NSInteger)cellPad
|
||||
{
|
||||
if (self.arrayImageView == nil) {
|
||||
self.arrayImageView = [[NSMutableArray alloc] init];
|
||||
}else{
|
||||
for (UMComImageView *imageView in self.arrayImageView) {
|
||||
[imageView removeFromSuperview];
|
||||
}
|
||||
[self.arrayImageView removeAllObjects];
|
||||
}
|
||||
self.cellPad = cellPad;
|
||||
self.placeholder = placeholder;
|
||||
|
||||
if (self.totalWidth == 0) {
|
||||
self.totalWidth = self.frame.size.width;
|
||||
}
|
||||
self.imageDeltaWidth = (self.totalWidth-cellPad*2)/3;
|
||||
for(int i = 0; i<9; i++)
|
||||
{
|
||||
UMComImageView *iv = [[[UMComImageView imageViewClassName] alloc] initWithPlaceholderImage:placeholder];
|
||||
[iv setIsAutoStart:NO];
|
||||
|
||||
iv.tag = i + 100;
|
||||
|
||||
[iv setCacheSecondes:A_WEEK_SECONDES];
|
||||
|
||||
[iv setFrame:getImageViewRect(i,self.imageDeltaWidth, cellPad)];
|
||||
|
||||
iv.userInteractionEnabled = YES;
|
||||
|
||||
[self.arrayImageView addObject:iv];
|
||||
}
|
||||
|
||||
[self setArray:images];
|
||||
}
|
||||
|
||||
#pragma mark 根据size截取图片中间矩形区域的图片 这里的size是正方形
|
||||
- (void)setArray:(NSArray *)array
|
||||
{
|
||||
self.imageModels = array;
|
||||
if([array count])
|
||||
{
|
||||
// CGSize size = getGridViewSize(array, self.cellPad, self.imageDeltaWidth);
|
||||
|
||||
// [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, size.height)];
|
||||
|
||||
int curImageCount = 0;
|
||||
|
||||
for (int i = 0;i < array.count;i++)
|
||||
{
|
||||
UMComImageUrl *imageModel = [array objectAtIndex:i];
|
||||
if (curImageCount < self.arrayImageView.count) {
|
||||
UMComImageView *iv = self.arrayImageView[curImageCount];
|
||||
iv.needCutOff = YES;
|
||||
if (iv.superview != self) {
|
||||
[self addSubview:iv];
|
||||
}
|
||||
[iv setImageURL:imageModel.small_url_string placeHolderImage:self.placeholder];
|
||||
curImageCount++;
|
||||
//添加触控
|
||||
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
|
||||
[iv addGestureRecognizer:tapGesture];
|
||||
}
|
||||
}
|
||||
|
||||
for (NSInteger i = array.count; i < 9; i++) {
|
||||
UMComImageView *iv = self.arrayImageView[i];
|
||||
[iv removeFromSuperview];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.frame = CGRectZero;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeAllSubviews
|
||||
{
|
||||
for(UMComImageView *iv in self.arrayImageView)
|
||||
{
|
||||
[iv removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tapImageView:(UITapGestureRecognizer *)tapGesture
|
||||
{
|
||||
|
||||
NSInteger index = -1;
|
||||
|
||||
CGPoint point = [tapGesture locationInView:self];
|
||||
|
||||
for(UMComImageView *iv in self.arrayImageView)
|
||||
{
|
||||
if(CGRectContainsPoint(iv.frame, point))
|
||||
{
|
||||
index = iv.tag - 100;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(index == -1)
|
||||
{
|
||||
UMLog(@"sorry,you didn't select the imageview");
|
||||
return;
|
||||
}
|
||||
self.viewerController = [[UMComSimpleGridViewerController alloc] initWithArray:self.imageModels index:index];
|
||||
[self.viewerController setCacheSecondes:A_WEEK_SECONDES];
|
||||
|
||||
self.viewerController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
||||
|
||||
if (self.TapInImage) {
|
||||
self.TapInImage(self.viewerController,self.arrayImageView[index]);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setPresentFatherViewController:(UIViewController *)viewController
|
||||
{
|
||||
self.fatherController = viewController;
|
||||
}
|
||||
|
||||
- (void)setCacheSecondes:(NSTimeInterval)secondes
|
||||
{
|
||||
for(UMComImageView *iv in self.arrayImageView)
|
||||
{
|
||||
[iv setCacheSecondes:secondes];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startDownload
|
||||
{
|
||||
for(UMComImageView *iv in self.arrayImageView)
|
||||
{
|
||||
[iv startImageLoad];
|
||||
}
|
||||
}
|
||||
@end
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// UMComGridViewerController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by luyiyuan on 14/9/2.
|
||||
// Copyright (c) 2014年 luyiyuan. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UMImageProgressView.h"
|
||||
|
||||
@interface UMComSimpleGridViewerController : UIViewController<UIScrollViewDelegate>
|
||||
|
||||
- (id)initWithArray:(NSArray *)array index:(NSUInteger)index;
|
||||
|
||||
- (void)setArray:(NSArray *)array index:(NSUInteger)index;
|
||||
|
||||
//默认一周(60*60*24*7)
|
||||
- (void)setCacheSecondes:(NSTimeInterval)secondes;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UMZoomSimpleScrollView : UIScrollView<UIScrollViewDelegate,UMImageViewDelegate, UIActionSheetDelegate>
|
||||
|
||||
@property (nonatomic, strong) UMImageProgressView *imageView;
|
||||
|
||||
//默认一周(60*60*24*7)
|
||||
- (void)setCacheSecondes:(NSTimeInterval)secondes;
|
||||
|
||||
- (void)startDownload;
|
||||
|
||||
@end
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
//
|
||||
// UMComGridViewerController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by luyiyuan on 14/9/2.
|
||||
// Copyright (c) 2014年 luyiyuan. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComSimpleGridViewerController.h"
|
||||
#import "UMImageProgressView.h"
|
||||
#import "UMComShowToast.h"
|
||||
#import <UMComDataStorage/UMComImageUrl.h>
|
||||
|
||||
typedef enum {
|
||||
preImage = 0,
|
||||
curImage = 1,
|
||||
rearImage = 2,
|
||||
}ImageLocation;
|
||||
#define A_WEEK_SECONDES (60*60*24*7)
|
||||
|
||||
@interface UMComSimpleGridViewerController ()
|
||||
@property (strong,nonatomic) UIPageControl *pageControl;
|
||||
@property (strong,nonatomic) UIScrollView *scrollView;
|
||||
@property (nonatomic,strong) NSArray *imageModels;
|
||||
@property (nonatomic,strong) NSMutableArray *arrayImageView;
|
||||
@property (nonatomic,strong) NSMutableArray *contentViews;
|
||||
@property (nonatomic,assign) NSInteger totalPageCount;
|
||||
@property (nonatomic,assign) NSInteger currentPageIndex;
|
||||
|
||||
@end
|
||||
|
||||
@implementation UMComSimpleGridViewerController
|
||||
{
|
||||
BOOL fisrtime;
|
||||
}
|
||||
|
||||
- (id)initWithArray:(NSArray *)array index:(NSUInteger)index
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if(self)
|
||||
{
|
||||
self.arrayImageView = [[NSMutableArray alloc] init];
|
||||
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
|
||||
self.scrollView.pagingEnabled = YES;
|
||||
self.scrollView.showsHorizontalScrollIndicator = NO;
|
||||
self.scrollView.showsVerticalScrollIndicator = NO;
|
||||
[self.scrollView setDelegate:self];
|
||||
|
||||
for(int i=0;i<3; i++)
|
||||
{
|
||||
UMZoomSimpleScrollView *zoomScrollView = [[UMZoomSimpleScrollView alloc]initWithFrame:CGRectMake(i*self.view.bounds.size.width, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
|
||||
UMImageProgressView *iv = [[UMImageProgressView alloc] initWithFrame:CGRectMake(0, 0, zoomScrollView.frame.size.width, zoomScrollView.frame.size.height)];
|
||||
iv.isAutoStart = NO;
|
||||
[iv setTag:i];
|
||||
[iv setCacheSecondes:A_WEEK_SECONDES];
|
||||
zoomScrollView.imageView = iv;
|
||||
[self.arrayImageView addObject:zoomScrollView];
|
||||
}
|
||||
|
||||
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 20, self.view.bounds.size.width, 20)];
|
||||
[self.view addSubview:self.scrollView];
|
||||
[self.view addSubview:self.pageControl];
|
||||
self.view.backgroundColor = [UIColor blackColor];
|
||||
|
||||
//添加触控
|
||||
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
|
||||
[self.view addGestureRecognizer:tapGesture];
|
||||
[self setArray:array index:index];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setArray:(NSArray *)array index:(NSUInteger)index
|
||||
{
|
||||
fisrtime = YES;
|
||||
self.imageModels = array;
|
||||
|
||||
NSUInteger count = [array count];
|
||||
if (count <= 9) {
|
||||
[self.pageControl setNumberOfPages:count];
|
||||
self.pageControl.currentPage = index;
|
||||
}
|
||||
self.currentPageIndex = index;
|
||||
self.contentViews = [NSMutableArray arrayWithCapacity:3];
|
||||
self.totalPageCount = count;
|
||||
[self configContentView];
|
||||
}
|
||||
|
||||
- (void)tapImageView:(UITapGestureRecognizer *)tapGesture
|
||||
{
|
||||
[self dismissViewControllerAnimated:YES completion:^{
|
||||
for (UMZoomSimpleScrollView *zoomView in self.arrayImageView) {
|
||||
zoomView.zoomScale = 1.0;
|
||||
zoomView.imageView.center = CGPointMake(zoomView.frame.size.width/2, zoomView.frame.size.height/2);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
//默认一周(60*60*24*7)
|
||||
- (void)setCacheSecondes:(NSTimeInterval)secondes
|
||||
{
|
||||
for(UMZoomSimpleScrollView *iv in self.arrayImageView)
|
||||
{
|
||||
[iv setCacheSecondes:secondes];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
self.scrollView.delegate = self;
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
self.scrollView.delegate = nil;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
{
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||
{
|
||||
if (scrollView.contentOffset.x >= (2*CGRectGetWidth(scrollView.frame))) {
|
||||
self.currentPageIndex = [self getValidNextPageIndexWithPageIndext:self.currentPageIndex+1];
|
||||
[self configContentView];
|
||||
}
|
||||
if (scrollView.contentOffset.x <= 0) {
|
||||
self.currentPageIndex = [self getValidNextPageIndexWithPageIndext:self.currentPageIndex-1];
|
||||
[self configContentView];
|
||||
}
|
||||
self.pageControl.currentPage = self.currentPageIndex;
|
||||
}
|
||||
|
||||
|
||||
- (void)setTotalPageCount:(NSInteger)totalPageCount
|
||||
{
|
||||
_totalPageCount = totalPageCount;
|
||||
if (_totalPageCount > 0) {
|
||||
if (_totalPageCount == 1) {
|
||||
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
|
||||
self.scrollView.contentOffset = CGPointMake(0, 0);
|
||||
self.scrollView.scrollEnabled = NO;
|
||||
}else{
|
||||
self.scrollView.contentSize = CGSizeMake(3*CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
|
||||
self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width, 0);
|
||||
self.scrollView.scrollEnabled = YES;
|
||||
}
|
||||
|
||||
}else{
|
||||
[self.contentViews removeAllObjects];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)configContentView
|
||||
{
|
||||
[self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
||||
[self setScrollViewContentDataSource];
|
||||
NSInteger counter = 0;
|
||||
for (UMZoomSimpleScrollView *contenView in self.contentViews) {
|
||||
contenView.frame = CGRectMake(self.scrollView.frame.size.width *counter+((self.scrollView.frame.size.width - contenView.frame.size.width)/2), 0, contenView.frame.size.width, contenView.frame.size.height);
|
||||
counter ++;
|
||||
[contenView startDownload];
|
||||
[self.scrollView addSubview:contenView];
|
||||
}
|
||||
[self.scrollView setContentOffset:CGPointMake(self.view.bounds.size.width, 0.0f) animated:NO];
|
||||
}
|
||||
|
||||
- (UMZoomSimpleScrollView *)zoomScrollViewWithPageIndex:(NSInteger)pageIndex imageLocation:(ImageLocation)imageLocation
|
||||
{
|
||||
//
|
||||
if (self.imageModels.count > 0) {
|
||||
UMZoomSimpleScrollView *zoomView = nil;
|
||||
if (imageLocation == preImage) {
|
||||
zoomView = self.arrayImageView[0];
|
||||
}else if (imageLocation == curImage){
|
||||
zoomView = self.arrayImageView[1];
|
||||
}else{
|
||||
zoomView = self.arrayImageView[2];
|
||||
}
|
||||
if (zoomView.zoomScale > 1) {
|
||||
[zoomView setZoomScale:1 animated:NO];
|
||||
}
|
||||
if (self.imageModels.count > pageIndex) {
|
||||
;
|
||||
UMComImageUrl *imageModel = self.imageModels[pageIndex];
|
||||
zoomView.imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
[zoomView.imageView setImageURL:[NSURL URLWithString:imageModel.large_url_string]];
|
||||
[zoomView.imageView setThumImageViewUrl:imageModel.small_url_string];
|
||||
}
|
||||
return zoomView;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
//获取将要加载图片
|
||||
- (void)setScrollViewContentDataSource
|
||||
{
|
||||
[self.contentViews removeAllObjects];
|
||||
@try {
|
||||
NSInteger prePageIndex = [self getValidNextPageIndexWithPageIndext:self.currentPageIndex-1];
|
||||
NSInteger rearPageIndex = [self getValidNextPageIndexWithPageIndext:self.currentPageIndex+1];
|
||||
|
||||
UMZoomSimpleScrollView *resaultView = [self zoomScrollViewWithPageIndex:prePageIndex imageLocation:preImage];
|
||||
if(resaultView){
|
||||
[self.contentViews addObject:resaultView];
|
||||
}
|
||||
resaultView = [self zoomScrollViewWithPageIndex:self.currentPageIndex imageLocation:curImage];
|
||||
if(resaultView){
|
||||
[self.contentViews addObject:resaultView];
|
||||
}
|
||||
resaultView = [self zoomScrollViewWithPageIndex:rearPageIndex imageLocation:rearImage];
|
||||
if(resaultView){
|
||||
[self.contentViews addObject:resaultView];
|
||||
}
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"exception:%@", exception);
|
||||
}
|
||||
@finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)getValidNextPageIndexWithPageIndext:(NSInteger)currentPageIndex;
|
||||
{
|
||||
if (currentPageIndex == -1) {
|
||||
return self.totalPageCount - 1;
|
||||
}else if (currentPageIndex == self.totalPageCount || currentPageIndex < -1){
|
||||
return 0;
|
||||
}else if (currentPageIndex > self.totalPageCount){
|
||||
return self.totalPageCount - 1;
|
||||
}else{
|
||||
return currentPageIndex;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UMZoomSimpleScrollView
|
||||
{
|
||||
UIActionSheet *actionSheet;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.delegate = self;
|
||||
self.showsHorizontalScrollIndicator = NO;
|
||||
self.showsVerticalScrollIndicator = NO;
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(saveImageToAssest:)];
|
||||
longPress.numberOfTouchesRequired = 1;
|
||||
[self addGestureRecognizer:longPress];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setImageView:(UMImageProgressView *)imageView
|
||||
{
|
||||
_imageView = imageView;
|
||||
_imageView.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
|
||||
|
||||
_imageView.backgroundColor = [UIColor clearColor];
|
||||
if (imageView.isCacheImage) {
|
||||
self.minimumZoomScale = 1.0;
|
||||
self.maximumZoomScale = 5.0;
|
||||
} else{
|
||||
self.minimumZoomScale = 1.0;
|
||||
self.maximumZoomScale = 1.0;
|
||||
}
|
||||
[self addSubview:_imageView];
|
||||
}
|
||||
|
||||
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
|
||||
{
|
||||
return self.imageView;
|
||||
}
|
||||
|
||||
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
|
||||
{
|
||||
CGFloat offsetX = (scrollView.bounds.size.width > scrollView.contentSize.width)?
|
||||
(scrollView.bounds.size.width - scrollView.contentSize.width) /2 : 0.0;
|
||||
CGFloat offsetY = (scrollView.bounds.size.height > scrollView.contentSize.height)?
|
||||
(scrollView.bounds.size.height - scrollView.contentSize.height) /2 : 0.0;
|
||||
self.imageView.center = CGPointMake(scrollView.contentSize.width /2 + offsetX,scrollView.contentSize.height /2 + offsetY);
|
||||
}
|
||||
|
||||
//默认一周(60*60*24*7)
|
||||
- (void)setCacheSecondes:(NSTimeInterval)secondes
|
||||
{
|
||||
[self.imageView setCacheSecondes:secondes];
|
||||
}
|
||||
|
||||
- (void)startDownload
|
||||
{
|
||||
[self.imageView startImageLoad];
|
||||
}
|
||||
|
||||
- (void)saveImageToAssest:(UILongPressGestureRecognizer *)longPress
|
||||
{
|
||||
if (longPress.state == UIGestureRecognizerStateBegan) {
|
||||
if (![actionSheet isVisible]) {
|
||||
actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:UMComLocalizedString(@"um_com_cancel", @"取消") destructiveButtonTitle:UMComLocalizedString(@"um_com_saveImageToAlbum", @"保存图片到相册")otherButtonTitles:nil, nil];
|
||||
if (!actionSheet.superview) {
|
||||
[actionSheet showInView:self.superview];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
|
||||
{
|
||||
if (buttonIndex == 0) {
|
||||
if (self.imageView.image) {
|
||||
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 指定回调方法
|
||||
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
|
||||
{
|
||||
[UMComShowToast saveIamgeResultNotice:error];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// UMComHorizonMenuView.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 15/11/26.
|
||||
// Copyright © 2015年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class UMComSimpleHorizonCollectionCell,UMComSimpleHorizonMenuView,UMComDropdownColumnCell;
|
||||
|
||||
|
||||
@protocol UMComSimpleHorizonMenuViewDelegate <NSObject>
|
||||
|
||||
@optional;
|
||||
|
||||
//- (NSInteger)numberOfRowInHorizonCollectionView:(UMComHorizonMenuView *)collectionView;
|
||||
//
|
||||
//- (void)horizonCollectionView:(UMComHorizonMenuView *)collectionView reloadCell:(UMComHorizonCollectionCell *)cell atIndexPath:(NSIndexPath *)indexPath;
|
||||
//
|
||||
- (void)horizonCollectionView:(UMComSimpleHorizonMenuView *)collectionView didSelectedColumn:(NSInteger)column;
|
||||
//
|
||||
//- (UIImage *)horizonCollectionView:(UMComHorizonMenuView *)collectionView imageForIndexPath:(NSIndexPath *)indexPath;
|
||||
//
|
||||
//- (UIImage *)horizonCollectionView:(UMComHorizonMenuView *)collectionView hilightImageForIndexPath:(NSIndexPath *)indexPath;
|
||||
//
|
||||
//- (NSString *)horizonCollectionView:(UMComHorizonMenuView *)collectionView titleForIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
@end
|
||||
|
||||
@interface UMComSimpleHorizonMenuView : UIView
|
||||
|
||||
@property (nonatomic, assign) BOOL isHighLightWhenDidSelected;
|
||||
|
||||
@property (nonatomic, assign) BOOL showScrollIndicator;
|
||||
|
||||
@property (nonatomic, strong) UIView *bottomLine;
|
||||
|
||||
@property (nonatomic, readonly) NSInteger currentIndex;
|
||||
|
||||
@property (nonatomic, readonly) NSInteger lastIndex;
|
||||
|
||||
@property (nonatomic, copy) UIColor *titleHightColor;
|
||||
|
||||
@property (nonatomic, copy) UIColor *titleColor;
|
||||
|
||||
@property (nonatomic, strong) UIImageView *scrollIndicatorView;
|
||||
|
||||
@property (nonatomic, strong) UIView *topLine;
|
||||
|
||||
@property (nonatomic, strong) NSArray *titlesArray;
|
||||
|
||||
@property (nonatomic, strong) UIFont *titleFont;
|
||||
|
||||
@property (nonatomic, weak) id<UMComSimpleHorizonMenuViewDelegate> cellDelegate;
|
||||
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)titles;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame;
|
||||
|
||||
- (void)startIndex:(NSInteger)index;
|
||||
|
||||
- (void)reloadData;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UMComSimpleHorizonCollectionCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) UIImageView *imageView;
|
||||
|
||||
@property (nonatomic, strong) UILabel *label;
|
||||
|
||||
@property (nonatomic, assign) NSInteger index;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
//
|
||||
// UMComHorizonMenuView.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 15/11/26.
|
||||
// Copyright © 2015年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComSimpleHorizonMenuView.h"
|
||||
#import "UMComResouceDefines.h"
|
||||
|
||||
@interface UMComSimpleHorizonMenuView ()<UICollectionViewDataSource, UICollectionViewDelegate>
|
||||
|
||||
@property (nonatomic, strong) UICollectionViewFlowLayout *currentLayout;
|
||||
|
||||
@property (nonatomic, strong) NSMutableDictionary *indexPathsDict;
|
||||
|
||||
@property (nonatomic, assign) BOOL isTheFirstTime;
|
||||
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
|
||||
@property (nonatomic,strong) NSMutableArray* cellCenterXArray;//cell的中心点坐标Array
|
||||
|
||||
@end
|
||||
|
||||
@implementation UMComSimpleHorizonMenuView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)titles;
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.titlesArray = titles;
|
||||
[self initSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [self initWithFrame:frame titles:nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)initSubViews
|
||||
{
|
||||
self.cellCenterXArray = [NSMutableArray arrayWithCapacity:2];
|
||||
|
||||
UICollectionViewFlowLayout *currentLayout = [[UICollectionViewFlowLayout alloc]init];
|
||||
currentLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
NSInteger itemCount = self.titlesArray.count;
|
||||
if (itemCount == 0) {
|
||||
itemCount = 1;
|
||||
}
|
||||
currentLayout.itemSize = CGSizeMake(self.frame.size.width/itemCount, self.frame.size.height);
|
||||
// currentLayout.sectionInset = UIEdgeInsetsMake(0.5, 0.5, 0.5, 0.5);
|
||||
self.currentLayout = currentLayout;
|
||||
|
||||
_isTheFirstTime = YES;
|
||||
_indexPathsDict = [NSMutableDictionary dictionary];
|
||||
|
||||
self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:currentLayout];
|
||||
self.collectionView.dataSource = self;
|
||||
self.collectionView.delegate = self;
|
||||
[self.collectionView registerClass:[UMComSimpleHorizonCollectionCell class] forCellWithReuseIdentifier:@"UMComHorizonCollectionCell"];
|
||||
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.collectionView.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:_collectionView];
|
||||
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
// self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
self.titleFont = [UIFont systemFontOfSize:18];
|
||||
|
||||
self.titleColor = [UIColor blackColor];
|
||||
self.titleHightColor = [UIColor blackColor];
|
||||
|
||||
//不允许滚动,防止出现滚动条
|
||||
self.collectionView.scrollEnabled = NO;
|
||||
}
|
||||
|
||||
- (void)reloadData
|
||||
{
|
||||
[self.collectionView reloadData];
|
||||
}
|
||||
|
||||
- (void)setShowScrollIndicator:(BOOL)showScrollIndicator
|
||||
{
|
||||
_showScrollIndicator = showScrollIndicator;
|
||||
if (_showScrollIndicator == YES) {
|
||||
self.scrollIndicatorView = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.collectionView.frame.size.height, self.frame.size.width, 1)];
|
||||
self.scrollIndicatorView.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:self.scrollIndicatorView];
|
||||
}else{
|
||||
_scrollIndicatorView.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
//- (void)startIndex:(NSInteger)index
|
||||
//{
|
||||
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
|
||||
// __weak typeof(self) weakSelf = self;
|
||||
// [UIView animateWithDuration:0.25 animations:^{
|
||||
//
|
||||
// }];
|
||||
//}
|
||||
#pragma mark -
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return self.titlesArray.count;
|
||||
}
|
||||
|
||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
UMComSimpleHorizonCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UMComHorizonCollectionCell" forIndexPath:indexPath];
|
||||
cell.index = indexPath.row;
|
||||
cell.label.font = self.titleFont;
|
||||
cell.label.text = self.titlesArray[indexPath.row];
|
||||
if (self.currentIndex == indexPath.row) {
|
||||
cell.label.textColor = self.titleHightColor;
|
||||
}else{
|
||||
cell.label.textColor = self.titleColor;
|
||||
}
|
||||
//设置中心点
|
||||
CGFloat cellCenterX = cell.center.x;
|
||||
if (self.cellCenterXArray.count < self.titlesArray.count) {
|
||||
self.cellCenterXArray[indexPath.row] = @(cellCenterX);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// UMComHorizonCollectionCell *cell = (UMComHorizonCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
_lastIndex = self.currentIndex;
|
||||
_currentIndex = indexPath.row;
|
||||
|
||||
if (self.cellDelegate && [self.cellDelegate respondsToSelector:@selector(horizonCollectionView:didSelectedColumn:)]) {
|
||||
|
||||
//选中的时候,动画scrollIndicatorView
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
NSNumber* centerXNumber = weakSelf.cellCenterXArray[indexPath.row];
|
||||
CGFloat centerX = centerXNumber.floatValue;
|
||||
CGFloat centerY = weakSelf.scrollIndicatorView.center.y;
|
||||
weakSelf.scrollIndicatorView.center = CGPointMake(centerX, centerY);
|
||||
}];
|
||||
|
||||
[self.cellDelegate horizonCollectionView:self didSelectedColumn:indexPath.row];
|
||||
}
|
||||
[self reloadData];
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSInteger itemCount = self.titlesArray.count;
|
||||
if (itemCount == 0) {
|
||||
itemCount = 1;
|
||||
}
|
||||
CGSize itemSize = CGSizeMake(collectionView.frame.size.width/itemCount, collectionView.frame.size.height);
|
||||
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)collectionViewLayout;
|
||||
layout.minimumLineSpacing = 0;
|
||||
layout.minimumInteritemSpacing = 0;
|
||||
CGRect frame = self.scrollIndicatorView.frame;
|
||||
frame.size.width = itemSize.width;
|
||||
self.scrollIndicatorView.frame = frame;
|
||||
return itemSize;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Only override drawRect: if you perform custom drawing.
|
||||
// An empty implementation adversely affects performance during animation.
|
||||
- (void)drawRect:(CGRect)rect {
|
||||
// Drawing code
|
||||
}
|
||||
*/
|
||||
|
||||
//- (void)drawRect:(CGRect)rect
|
||||
//{
|
||||
// UIColor *color = [UIColor redColor];
|
||||
// CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
// CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
|
||||
// CGContextFillRect(context, rect);
|
||||
// CGContextSetStrokeColorWithColor(context, color.CGColor);
|
||||
// CGFloat itemSpaceTopEdge = 6;
|
||||
// for (int index = 1; index < self.itemCount; index++) {
|
||||
// CGContextStrokeRect(context, CGRectMake(index * self.itemSize.width, itemSpaceTopEdge, self.itemSpace, rect.size.height - itemSpaceTopEdge*2));
|
||||
// }
|
||||
//}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UMComSimpleHorizonCollectionCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.contentView.backgroundColor = [UIColor clearColor];
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height-1)];
|
||||
self.imageView.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:self.imageView];
|
||||
|
||||
self.label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-1)];
|
||||
self.label.backgroundColor = [UIColor clearColor];
|
||||
self.label.font = UMComFontNotoSansLightWithSafeSize(15);
|
||||
self.label.textAlignment = NSTextAlignmentCenter;
|
||||
self.label.textColor = [UIColor blackColor];
|
||||
self.label.numberOfLines = 0;
|
||||
[self.contentView addSubview:self.label];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// UMComCustomMenuViewController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/11.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UMComViewController.h"
|
||||
#import "UMComSimpleHorizonMenuView.h"
|
||||
|
||||
@interface UMComCustomMenuViewController : UMComViewController<UMComSimpleHorizonMenuViewDelegate>
|
||||
|
||||
/**
|
||||
*子ViewController
|
||||
*/
|
||||
@property (nonatomic, strong) NSArray *subViewControllers;
|
||||
|
||||
/**
|
||||
* title 菜单表
|
||||
*/
|
||||
@property (nonatomic, strong) NSArray *titlesArray;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@property (nonatomic, strong) UMComSimpleHorizonMenuView *menuView;
|
||||
|
||||
/**
|
||||
*显示表现序号
|
||||
*/
|
||||
@property (nonatomic, assign) NSInteger showIndex;
|
||||
|
||||
|
||||
@property (nonatomic, strong) UIView *userMessageView;
|
||||
/**
|
||||
* 点击发现
|
||||
*/
|
||||
- (void)onTouchDiscover;
|
||||
|
||||
- (void)didTransitionToIndex:(NSInteger)index;
|
||||
|
||||
@end
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// UMComCustomMenuViewController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/11.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComCustomMenuViewController.h"
|
||||
#import "UIViewController+UMComAddition.h"
|
||||
#import "UMComResouceDefines.h"
|
||||
#import <UMComFoundation/UMComKit+Color.h>
|
||||
|
||||
@interface UMComCustomMenuViewController ()
|
||||
|
||||
//- (UIView *)creatNoticeViewWithOriginX:(CGFloat)originX;
|
||||
@end
|
||||
|
||||
@implementation UMComCustomMenuViewController
|
||||
|
||||
@synthesize showIndex = _showIndex;
|
||||
@synthesize subViewControllers = _subViewControllers;
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
// UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithImage:UMComSimpleImageWithImageName(@"user") style:UIBarButtonItemStylePlain target:self action:@selector(onTouchDiscover)];
|
||||
|
||||
UIButton* disCoverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
disCoverBtn.frame = CGRectMake(0, 0, 40, 44);
|
||||
[disCoverBtn setImage:UMComSimpleImageWithImageName(@"user") forState:UIControlStateNormal];
|
||||
[disCoverBtn addTarget:self action:@selector(onTouchDiscover) forControlEvents:UIControlEventTouchUpInside];
|
||||
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:disCoverBtn];
|
||||
[rightButton setWidth:44];
|
||||
|
||||
self.userMessageView = [self creatNoticeViewWithOriginX:25 withOriginY:10];
|
||||
|
||||
self.userMessageView.backgroundColor = [UIColor redColor];
|
||||
[disCoverBtn addSubview:self.userMessageView];
|
||||
|
||||
self.navigationItem.rightBarButtonItem = rightButton;
|
||||
|
||||
[self createMenuView];
|
||||
// [self.navigationController.navigationBar addSubview:_menuView];
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
- (UIView *)creatNoticeViewWithOriginX:(CGFloat)originX withOriginY:(CGFloat)originY
|
||||
{
|
||||
CGFloat noticeViewWidth = 7;
|
||||
UIView *itemNoticeView = [[UIView alloc]initWithFrame:CGRectMake(originX,originY, noticeViewWidth, noticeViewWidth)];
|
||||
itemNoticeView.backgroundColor = [UIColor redColor];
|
||||
itemNoticeView.layer.cornerRadius = noticeViewWidth/2;
|
||||
itemNoticeView.clipsToBounds = YES;
|
||||
itemNoticeView.hidden = YES;
|
||||
return itemNoticeView;
|
||||
}
|
||||
|
||||
- (void)onTouchDiscover
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
}
|
||||
|
||||
- (void)createMenuView
|
||||
{
|
||||
CGFloat menuWidth = 120;
|
||||
self.menuView = [[UMComSimpleHorizonMenuView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-UMComWidthScaleBetweenCurentScreenAndiPhone6Screen(menuWidth/2), 0, UMComWidthScaleBetweenCurentScreenAndiPhone6Screen(menuWidth), 40) titles:self.titlesArray];
|
||||
self.menuView.cellDelegate = self;
|
||||
self.menuView.showScrollIndicator = YES;
|
||||
|
||||
//更新menuView的位置,宽度会根据cell的宽度变化
|
||||
CGRect scrollIndicatorViewRC = self.menuView.scrollIndicatorView.frame;
|
||||
scrollIndicatorViewRC.origin.y -= 2;
|
||||
scrollIndicatorViewRC.size.height = 2;
|
||||
scrollIndicatorViewRC.size.width = 70;
|
||||
|
||||
self.menuView.scrollIndicatorView.frame = scrollIndicatorViewRC;
|
||||
self.menuView.scrollIndicatorView.backgroundColor = UMComColorWithHexString(FontColorBlue);
|
||||
|
||||
self.menuView.titleHightColor = UMComColorWithHexString(@"333333");
|
||||
self.menuView.titleColor = UMComColorWithHexString(@"999999");
|
||||
|
||||
self.menuView.backgroundColor = [UIColor clearColor];
|
||||
self.navigationItem.titleView = _menuView;
|
||||
}
|
||||
|
||||
- (void)setTitlesArray:(NSArray *)titlesArray
|
||||
{
|
||||
_titlesArray = titlesArray;
|
||||
self.menuView.titlesArray = titlesArray;
|
||||
[self.menuView reloadData];
|
||||
}
|
||||
|
||||
#pragma mark - menuViewDelegate
|
||||
|
||||
- (void)horizonCollectionView:(UMComSimpleHorizonMenuView *)collectionView didSelectedColumn:(NSInteger)column
|
||||
{
|
||||
self.showIndex = column;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - set and get
|
||||
- (void)setSubViewControllers:(NSArray *)subViewControllers
|
||||
{
|
||||
_subViewControllers = subViewControllers;
|
||||
for (UIViewController *viewController in _subViewControllers) {
|
||||
viewController.view.frame = self.view.bounds;
|
||||
[self addChildViewController:viewController];
|
||||
}
|
||||
if (_subViewControllers.count > 0) {
|
||||
[self transitionFromViewControllerAtIndex:_subViewControllers.count-1 toViewControllerAtIndex:self.showIndex animations:nil completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)subViewControllers
|
||||
{
|
||||
return _subViewControllers;
|
||||
}
|
||||
|
||||
|
||||
- (void)setShowIndex:(NSInteger)showIndex
|
||||
{
|
||||
_showIndex = showIndex;
|
||||
[self transitionFromViewControllerAtIndex:self.menuView.lastIndex toViewControllerAtIndex:_showIndex animations:nil completion:nil];
|
||||
[self didTransitionToIndex:showIndex];
|
||||
}
|
||||
|
||||
- (void)didTransitionToIndex:(NSInteger)index
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (NSInteger)showIndex
|
||||
{
|
||||
return _showIndex;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||||
// Get the new view controller using [segue destinationViewController].
|
||||
// Pass the selected object to the new view controller.
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// UMComFeedClickActionDelegate.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 15/5/22.
|
||||
// Copyright (c) 2015年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class UMComUser, UMComFeed,UMComComment,UMComTopic,UMComLike;
|
||||
@protocol UMComFeedClickActionDelegate <NSObject>
|
||||
|
||||
@optional;
|
||||
|
||||
- (void)customObj:(id)obj clickOnFeedCreator:(UMComUser *)user;
|
||||
- (void)customObj:(id)obj clickOnTopic:(UMComTopic *)topic;
|
||||
- (void)customObj:(id)obj clickOnFeedText:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnLikeFeed:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnCommentFeed:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnImageView:(UIImageView *)imageView complitionBlock:(void (^)(UIViewController *currentViewController))block;
|
||||
- (void)customObj:(id)obj clickOnURL:(NSString *)urlSring;
|
||||
|
||||
- (void)customObj:(id)obj clickOnOriginFeedText:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnLocationText:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnSpamFeed:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnDeleted:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnCopyFeed:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnShare:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnFavouratesFeed:(UMComFeed *)feed;
|
||||
- (void)customObj:(id)obj clickOnForward:(UMComFeed *)feed;
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user