UICollectionView(相簿大圖檢視)
#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(相簿大圖檢視)
#import <UIKit/UIKit.h> #import "BaseViewController.h" @interface FullAlbumViewController : BaseViewController<UIScrollVie
Android 廣告(banner)圖片輪播、圖片瀏覽、仿微信大圖檢視控制元件(支援視訊和gif圖片)、支援動態新增資料
之前專案需要做個仿微信檢視大圖,需要新增圓形下載進度,支援視訊和圖片切換等一系列功能控制元件,自己抽空把開發的自定義控制元件的成果重新構造、整理處理封裝成庫(aar),提供出來,有需要朋友,歡迎使用,如果有什麼建議歡迎留言或者GitHub上提issues
淺談Android多圖(包括大圖)上傳時的記憶體處理,防止記憶體溢位。
Android多圖上傳時,為了防止記憶體溢位,基本只要做好兩點就好了,一是及時釋放已經上傳完的圖片,以及在對圖片處理時,必須是一張一張來,因為對圖片的處理過程是最容易OOM的。 下面有簡單的程式碼說明下, 1、首先,圖片的model, ImageBean model中
Activity以對話方塊Dialog形式展現(顯示大圖)
1、設定螢幕高度寬度。 //視窗對齊螢幕寬度 Window win = this.getWindow(); win.getDecorView().setPadding(0, 0, 0, 0); WindowManager.LayoutParams lp =
WPF圖片瀏覽器(顯示大圖、小圖等)
1.概述 最近利用WPF做了一個圖片瀏覽器,能夠將資料夾中的所有圖片以小圖的形式顯示,並將選中的圖片以512*512大小顯示。顯示大圖當然用的是WPF自帶的Image控制元件,而顯示小圖則需要將所有的圖片放入ListBox控制元件中,ListB
一文詳解 LVS、Nginx 及 HAProxy 工作原理( 附大圖 )
當前大多數的網際網路系統都使用了伺服器叢集技術,叢集是將相同服務部署在多臺伺服器上構成一個叢集整體對外提供服務,這些叢集可以是 Web 應用伺服器叢集,也可以是資料庫伺服器叢集,還可以是分散式快取伺服器叢集等等。 在實際應用中,在 Web 伺服器叢集之前總會有一臺負載均
485. Max Consecutive Ones (最大連續數) by Python
大連 put int statistic inpu one emp bin 簡單 485. Max Consecutive Ones 題目: Given a binary array, find the maximum number of consecutive 1s in
HNU 13411 Reverse a Road II(最大流+BFS)經典
ret ring connect 我們 users directly void whether take Reverse a Road II Time Limit: 10000ms, Special Time Limit:25000ms,
mysql中varchar和char區別(思維導圖整理)
var 但是 系統 mysql 由於 varchar .html nbsp 了解 由於mysql一直是我的弱項(其實各方面我都是很弱的),所以最近在看msyql,正好看到varchar和char區別,所以整理一下,便於以後遺忘。 0.0圖片已經說明一切,但是系
hdu 1689 Alien’s Necklace (bfs層次圖剪枝)
line mic continue Go LG track BE font 方法 Alien’s Necklace Time Limit: 10000/
POJ 3692 Kindergarten(最大團問題)
nta class 怎麽 pro HP 思路 color 如何 online 題目鏈接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All
SPOJ:One piece(最大匹配問題)(Gut Problem!)
這一 bit 估值 clu 排除 DC multipl contain any One of DB and TN common interests is traveling. One day, they went to Grand Line and found One Pi
Bad Cowtractors(最大生成樹)
found ins -m 普裏姆算法 卡爾 eal following void HR Description Bessie has been hired to build a cheap internet network among Farmer John
poj Drainage Ditches(最大流入門)
minute ostream 代碼 gin ted pat 當前 earch http Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions:
K - Treasure Exploration (最大路徑覆蓋)
K - Treasure Exploration Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you eve
HDU3829:Cat VS Dog(最大獨立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 4751 &n
Newcoder 111 D.托米去購物(最大流-dinic)
Description 由於這裡什麼都沒有,於是他去超市選了很多生活用品,更多的是吃的,然後推著堆滿零食的購物車到櫃檯等待結賬。 當然,我們都知道他的錢包裡有很多錢。但是,作為一名為生活精打細算的男孩子,他更願意使用其他支付方式如:飯券,禮券,不同型別的優惠券等。但是飯券只能用於
SQL Server資料庫開發(4.索引和檢視)
一、索引 定義:是資料表中資料和相應儲存位置的列表。 作用:可以提高在表或檢視中查詢資料的速度。 1.分類:聚集索引,非聚集索引 聚集索引:指表中資料行的物理儲存順序與索引順序完全相同。 非聚集索引:不該表表中資料行的物理儲存位置,資料與索引分開儲存,通過索引指向的地址與表中的資
蟑螂隨機走動問題(資料結構圖問題)
一、問題概要 1.1 題 目: 《隨機走動》 1.2 初始條件: 一隻貪杯的蟑螂醺醺然在室內地面遊蕩。地面鋪滿方磚,共計m*n塊,構成大面積矩陣。蟑
HDU 3829 - Cat VS Dog(最大獨立集)
The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-an