#import <UIKit/UIKit.h>
#import "BaseViewController.h"
@interface FullAlbumViewController : BaseViewController<UIScrollViewDelegate,UIActionSheetDelegate>
@property (strong, nonatomic) NSArray *assetsArray;
@property (assign, nonatomic) NSInteger currentIndex;
@property (nonatomic,strong) NSString *path;
@end
#import "FullAlbumViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "FullImageCell.h"
static NSString *cellIdentifier = @"FullImageCell";
@interface FullAlbumViewController ()
<UICollectionViewDataSource, UICollectionViewDelegate>
{
UILabel * numLb;
UILabel * desLb;
int i;
//
}
@property (strong, nonatomic) UICollectionView *collectionView;
@end
@implementation FullAlbumViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// self.automaticallyAdjustsScrollViewInsets = NO;
// //确定是水平滚动,还是垂直滚动
UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH ) collectionViewLayout:flowLayout];
self.collectionView.dataSource=self;
self.collectionView.delegate=self;
self.collectionView.contentOffset = CGPointMake(_currentIndex * kScreenW, 0);
self.collectionView.pagingEnabled = YES;
//注册Cell,必须要有
[self.collectionView registerClass:[FullImageCell class] forCellWithReuseIdentifier:cellIdentifier];
[self.view addSubview:self.collectionView];
numLb = [self buildLabelWithFrame:CGRectMake(kScreenW - 150, kScreenH-50, 150, 50) backgroundColor:[UIColor clearColor] textColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:40] textAlignment:NSTextAlignmentRight text:[NSString stringWithFormat:@"%d/%lu",_currentIndex+1,(unsigned long)self.assetsArray.count]];
[self.view addSubview:numLb];
desLb = [self buildLabelWithFrame:CGRectMake(0, kScreenH-50, kScreenW - 150, 50) backgroundColor:[UIColor clearColor] textColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:12] textAlignment:NSTextAlignmentLeft text:@""];
desLb.numberOfLines = 0;
[self.view addSubview:desLb];
/*
self.view.backgroundColor = [UIColor redColor];
UIScrollView *scrollView =[[ UIScrollView alloc]initWithFrame:self.view.frame];
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(kScreenW*self.assetsArray.count, 0);
scrollView.contentOffset = CGPointMake(kScreenW*_currentIndex, 0);
scrollView.delegate = self;
scrollView.backgroundColor = [UIColor blackColor];
[self.view addSubview:scrollView];
for (i = 0; i<self.assetsArray.count; i++) {
scr= [[UIScrollView alloc]initWithFrame:CGRectMake(width(self.view)*i, 0, width(self.view), height(self.view))];
imageView =[[UIImageView alloc]initWithFrame:scr.frame];
// imageView.imageURL = [NSURL URLWithString:self.photoArray[i]];
NSString *ImagePath = [self.path stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.png",[self.assetsArray[i] objectForKey:@"imageName"]]];
imageView.image = [UIImage imageWithContentsOfFile:ImagePath];
CGFloat imgW = imageView.image.size.width;
CGFloat imgH = imageView.image.size.height;
CGFloat imgViewWid ;
CGFloat imgViewHie;
//判断图片实际大小是否大于屏幕尺寸 如果大于则定其宽度等于屏幕宽度 等比缩放图片
if (imgW>kScreenW) {
imgViewWid = kScreenW;
imgViewHie = kScreenW * imgH/imgW;
}else{
imgViewWid = imgW;
imgViewHie = imgH;
}
imageView.frame = CGRectMake(0, 0, imgViewWid, imgViewHie);
imageView.userInteractionEnabled = YES;
imageView.center = CGPointMake(kScreenW/2, kScreenH/2);
imageView.tag = 1000+i;
[scr addSubview:imageView];
[scr addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backView)]];
scr.backgroundColor = [UIColor blackColor];
[scrollView addSubview:scr];
numLb = [self buildLabelWithFrame:CGRectMake(width(self.view)-170, height(self.view)-100, 150, 100) backgroundColor:[UIColor clearColor] textColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:40] textAlignment:NSTextAlignmentRight text:[NSString stringWithFormat:@"%d/%lu",_currentIndex+1,(unsigned long)self.assetsArray.count]];
[self.view addSubview:numLb];
}
*/
}
-(void)backView
{
// [self.menuController popViewControllerAnimated:NO];
// [self.menuController pushViewController:nav withTransitionAnimator:[MDTransitionAnimatorFactory transitionAnimatorWithType:MDAnimationTypeSlideFromRight]];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
// numLb.text = @"";
int num = self.collectionView.contentOffset.x/width(self.view);
int allnum = self.collectionView.contentSize.width/width(self.view);
numLb.text = [NSString stringWithFormat:@"%d/%d",num+1,allnum];
desLb.text = [self.assetsArray[num] objectForKey:@"Location"];
// saveButton.tag = num;
NSLog(@"----------%d",num);
}
#pragma mark - <UICollectionViewDataSource>
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return [UIScreen mainScreen].bounds.size;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0.0f;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0.0f;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.assetsArray.count;
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FullImageCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
NSString *ImagePath = [self.path stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.png",[self.assetsArray[indexPath.row] objectForKey:@"imageName"]]];
cell.albumView.image = [UIImage imageWithContentsOfFile:ImagePath];
CGFloat imgW = cell.albumView.image.size.width;
CGFloat imgH = cell.albumView.image.size.height;
CGFloat imgViewWid ;
CGFloat imgViewHie;
//判断图片实际大小是否大于屏幕尺寸 如果大于则定其宽度等于屏幕宽度 等比缩放图片
if (imgW>kScreenW) {
imgViewWid = kScreenW;
imgViewHie = kScreenW * imgH/imgW;
}else{
imgViewWid = imgW;
imgViewHie = imgH;
}
cell.albumView.frame = CGRectMake(0, 0, imgViewWid, imgViewHie);
cell.albumView.userInteractionEnabled = YES;
cell.albumView.center = CGPointMake(kScreenW/2, kScreenH/2);
desLb.text = [self.assetsArray[indexPath.row] objectForKey:@"Location"];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.navigationController.navigationBarHidden) {
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
self.navigationController.navigationBarHidden = NO;
}
else {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
self.navigationController.navigationBarHidden = YES;
}
}
UICollectionView(相册大图查看)
最新推荐文章于 2024-07-01 14:00:00 发布