Initial commit
This commit is contained in:
+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
|
||||
Reference in New Issue
Block a user