亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

利用iOS實現(xiàn)系統(tǒng)相冊大圖瀏覽功能詳解

 更新時間:2017年09月19日 08:33:38   作者:laona  
查看大圖是們?nèi)粘i_發(fā)中經(jīng)常會遇到的一個需求,下面這篇文章主要給大家介紹了關(guān)于利用iOS實現(xiàn)系統(tǒng)相冊大圖瀏覽功能的相關(guān)資料,文中給出了詳細的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。

前言

本文主要給大家介紹了關(guān)于iOS實現(xiàn)系統(tǒng)相冊大圖瀏覽功能的相關(guān)資料,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細的介紹吧。

最終效果圖


大圖瀏覽

實現(xiàn)過程

  • 創(chuàng)建兩個UICollectionView分別放置大圖和縮略圖
  • 實現(xiàn)大圖和縮略圖的聯(lián)動
  • 實現(xiàn)當(dāng)前展示的大圖對應(yīng)的縮略圖放大效果

實現(xiàn)原理

創(chuàng)建collectionView非常簡單,只要正常創(chuàng)建就好,值得注意的是:由于需要當(dāng)前展示的圖片的縮略圖始終保持在屏幕中間位置,所以在創(chuàng)建縮略圖的collectionView的時候需要對collection View設(shè)置好便宜量。

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, (kScreenWidth - _itemWidth)/2, 0, (kScreenWidth - _itemWidth)/2);
}

實現(xiàn)上下聯(lián)動通過兩個block來實現(xiàn)

-(void)collectionViewDidScrollWithScrollBlock:(DidScrollBlock)didScrollBlcok;
-(void)collectionViewDidScrollWithScrollBlock:(IndexScrollBlock)didScrollBlcok;

實現(xiàn)當(dāng)前顯示縮略圖放大通過設(shè)置collectionView的UICollectionViewFlowLayout實現(xiàn)

IndexFlow *flowLayout = [[IndexFlow alloc] init];
self = [super initWithFrame:frame collectionViewLayout:flowLayout];

部分實現(xiàn)代碼

- (void)collectionViewDidScrollWithScrollBlock:(DidScrollBlock)didScrollBlcok{

self.didScrollBlcok = didScrollBlcok;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{

self.shouldDid = YES;

return YES;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
self.shouldDid = NO;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
 if (self.shouldDid) {
  if (self.didScrollBlcok) {
    self.didScrollBlcok(self);
  }
 }
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, (kScreenWidth - _itemWidth)/2, 0, (kScreenWidth - _itemWidth)/2);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(_itemWidth, self.height);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return _minLineSpacing;
}

縮略圖放大實現(xiàn)代碼

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)oldBounds
{
return YES;
}

-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
{
// 取出所有元素
NSArray *array = [super layoutAttributesForElementsInRect:rect];
// 可視區(qū)域
CGRect visibleRect;
visibleRect.origin = self.collectionView.contentOffset;
visibleRect.size = self.collectionView.bounds.size;  
for (UICollectionViewLayoutAttributes *attribute in array) {
  CGFloat distance = CGRectGetMidX(visibleRect) - attribute.center.x;
  CGFloat normalizedDistance = distance / ACTIVE_DISTANCE;
  if (ABS(distance) < ACTIVE_DISTANCE) {
    CGFloat zoom = 1 + ZOOM_FACTOR*(1 - ABS(normalizedDistance));
    attribute.transform3D = CATransform3DMakeScale(zoom, zoom, 1.0);
    attribute.zIndex = 1;
  }
}
return array;
}

/**
 * 設(shè)置collectionView停止?jié)L動那一刻的位置
 *
 * @param proposedContentOffset 原本collectionView停止?jié)L動那一刻的位置
 * @param velocity       速度
 *
 * @return 最終的位置
 */
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
{
CGFloat offsetAdjustment = MAXFLOAT;
CGFloat horizontalCenter = proposedContentOffset.x + (CGRectGetWidth(self.collectionView.bounds) / 2.0);
// 停止時刻的可視區(qū)域
CGRect targetRect = CGRectMake(proposedContentOffset.x, 0.0, self.collectionView.bounds.size.width, self.collectionView.bounds.size.height);
NSArray* array = [super layoutAttributesForElementsInRect:targetRect];
for (UICollectionViewLayoutAttributes* layoutAttributes in array) {
  CGFloat itemHorizontalCenter = layoutAttributes.center.x;
  if (ABS(itemHorizontalCenter - horizontalCenter) < ABS(offsetAdjustment)) {
    offsetAdjustment = itemHorizontalCenter - horizontalCenter;
  }
}
return CGPointMake(proposedContentOffset.x + offsetAdjustment, proposedContentOffset.y);
}

源碼下載:

Demo下載 (本地下載

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • iOS開發(fā)中實現(xiàn)一個簡單的圖片瀏覽器的實例講解

    iOS開發(fā)中實現(xiàn)一個簡單的圖片瀏覽器的實例講解

    這篇文章主要介紹了iOS開發(fā)中實現(xiàn)一個簡單的圖片瀏覽器的實例講解,代碼基礎(chǔ)傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2016-01-01
  • iOS 隱藏tabbar代碼詳解

    iOS 隱藏tabbar代碼詳解

    這篇文章主要介紹了iOS 隱藏tabbar代碼詳解的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • 詳解Objective-C設(shè)計模式編程中對備忘錄模式的運用

    詳解Objective-C設(shè)計模式編程中對備忘錄模式的運用

    這篇文章主要介紹了Objective-C設(shè)計模式編程中對備忘錄模式的運用,文中結(jié)合了Cocoa框架下應(yīng)用的實例來加以講解,需要的朋友可以參考下
    2016-03-03
  • iOS應(yīng)用開發(fā)中使用Auto Layout來適配不同屏幕尺寸

    iOS應(yīng)用開發(fā)中使用Auto Layout來適配不同屏幕尺寸

    這篇文章主要介紹了iOS應(yīng)用開發(fā)中使用Auto Layout來適配不同屏幕尺寸的方法,根據(jù)Xcode IDE下的實際調(diào)試步驟講解其用法,需要的朋友可以參考下
    2016-03-03
  • iOS開發(fā)中使用FMDB來使程序連接SQLite數(shù)據(jù)庫

    iOS開發(fā)中使用FMDB來使程序連接SQLite數(shù)據(jù)庫

    這篇文章主要介紹了iOS開發(fā)中使用FMDB來使程序連接SQLite數(shù)據(jù)庫,SQLite是一個簡單的嵌入式數(shù)據(jù)庫,非常適合輕量級使用,需要的朋友可以參考下
    2015-11-11
  • iOS開發(fā)之Quartz2D的介紹與使用詳解

    iOS開發(fā)之Quartz2D的介紹與使用詳解

    什么是Quartz2D?Quartz 2D是一個二維繪圖引擎,同時支持iOS和Mac系統(tǒng)。下面這篇文章主要介紹了iOS開發(fā)之Quartz2D的介紹與使用的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • iOS開發(fā)教程之XLForm的基本使用方法

    iOS開發(fā)教程之XLForm的基本使用方法

    XLForm 是最靈活且最強大的創(chuàng)建動態(tài)表單的iOS庫,下面這篇文章主要給大家介紹了關(guān)于iOS開發(fā)教程之XLForm的基本使用方法,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • 如何利用iCloud Drive同步Xcode配置詳解

    如何利用iCloud Drive同步Xcode配置詳解

    這篇文章主要給大家介紹了關(guān)于如何利用iCloud Drive同步Xcode配置的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • iOS16使用SwiftUI Charts創(chuàng)建折線圖實現(xiàn)實例

    iOS16使用SwiftUI Charts創(chuàng)建折線圖實現(xiàn)實例

    這篇文章主要為大家介紹了iOS16使用SwiftUI Charts創(chuàng)建折線圖實現(xiàn)實例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • iOS仿微博客戶端一條微博的展示效果

    iOS仿微博客戶端一條微博的展示效果

    這篇文章主要為大家詳細介紹了iOS仿微博客戶端,一條微博的布局,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評論