国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - IOS - iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

2021-01-11 16:53jiangamh IOS

這篇文章主要介紹了iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果的相關資料,需要的朋友可以參考下

以前瀑布流的時候使用過uicollectionview,但是那時使用的是系統自帶的uicollectionviewflowlayout布局,今天看文章,看到uicollectionviewflowlayout自定義相關的東西,于是動手寫了一個簡單圖片瀏覽的demo,熟練一些uicollectionviewflowlayout自定義布局。

?
1
2
3
4
5
#import <uikit/uikit.h>
 
@interface jwcollectionviewflowlayout : uicollectionviewflowlayout
 
@end

自定義uicollectionviewflowlayout,首先繼承uicollectionviewflowlayout,實現一下幾個方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#define screenwidth [uiscreen mainscreen].bounds.size.width
 
#define maxchangerange 100
 
#import "jwcollectionviewflowlayout.h"
 
@implementation jwcollectionviewflowlayout
 
-(void)preparelayout
{
 self.scrolldirection = uicollectionviewscrolldirectionhorizontal;
 self.itemsize = cgsizemake(300, 500);
}
 
- (bool)shouldinvalidatelayoutforboundschange:(cgrect)newbounds
{
 return yes;
}
 
- (nullable nsarray<__kindof uicollectionviewlayoutattributes *> *)layoutattributesforelementsinrect:(cgrect)rect
{
 nsarray *array = [super layoutattributesforelementsinrect:rect];
 
 cgrect visiblerect = cgrectmake(self.collectionview.contentoffset.x, 0, self.collectionview.bounds.size.width, self.collectionview.bounds.size.height);
 for (uicollectionviewlayoutattributes *attr in array)
 {
  if (cgrectintersectsrect(attr.frame, rect)) {
 
   bool isatright = yes;
   cgfloat distance = (attr.center.x - cgrectgetmidx(visiblerect));
   if (distance<0) {
    distance = -distance;
    isatright = no;
   }
   cgfloat precent ;
   if (distance < 180)
   {
    precent = 1.0;
   }
   else
   {
    precent = ((screenwidth / 2) - distance) / (screenwidth / 2);
   }
   catransform3d transform = catransform3didentity;
   transform.m34 = 1.0 / 600;
 
   if (precent < 0.5) {
    precent = 0.5;
   }
   transform = catransform3dscale(transform, 1, precent, 1);
   cgfloat p = isatright?m_pi_4:-m_pi_4;
   transform = catransform3drotate(transform, p * (1 - precent), 0, 1, 0);
   attr.transform3d = transform;
   attr.zindex = 1;
   attr.alpha = precent;
  }
 }
 
 return array;
}
 
- (cgpoint)targetcontentoffsetforproposedcontentoffset:(cgpoint)proposedcontentoffset withscrollingvelocity:(cgpoint)velocity
{
 cgfloat offset = maxfloat;
 
 cgfloat hcenter = proposedcontentoffset.x + (cgrectgetwidth(self.collectionview.bounds) / 2.0);
 
 cgrect currentrect = cgrectmake(proposedcontentoffset.x, 0, self.collectionview.bounds.size.width, self.collectionview.bounds.size.height);
 
 nsarray* array = [super layoutattributesforelementsinrect:currentrect];
 for (uicollectionviewlayoutattributes* layoutattributes in array)
 {
  cgfloat itemhorizontalcenter = layoutattributes.center.x;
  if (abs(itemhorizontalcenter - hcenter) < abs(offset))
  {
 
   offset = itemhorizontalcenter - hcenter;
  }
 }
 
 return cgpointmake(proposedcontentoffset.x + offset, proposedcontentoffset.y);
}

使用

?
1
2
3
4
5
6
7
8
9
10
11
12
13
-(void)setupui
{
 
 jwcollectionviewflowlayout *flowlayout = [[jwcollectionviewflowlayout alloc] init];
 uicollectionview *imgbrowseview = [[uicollectionview alloc] initwithframe:self.view.bounds collectionviewlayout:flowlayout];
 imgbrowseview.datasource = self;
 imgbrowseview.delegate = self;
 imgbrowseview.backgroundcolor = [uicolor whitecolor];
 [self.view addsubview:imgbrowseview];
 _imgbrowseview = imgbrowseview;
 
 [self.imgbrowseview registernib:[uinib nibwithnibname:@"custumcollectionviewcell" bundle:nil] forcellwithreuseidentifier:@"cell"];
}

demo:https://github.com/jiangtaidi/jwimagebrowsedemo.git

運行結果:

iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

以上就是本文的全部內容,希望對大家的學習有所幫助。

延伸 · 閱讀

精彩推薦
  • IOSiOS中MD5加密算法的介紹和使用

    iOS中MD5加密算法的介紹和使用

    MD5加密是最常用的加密方法之一,是從一段字符串中通過相應特征生成一段32位的數字字母混合碼。對輸入信息生成唯一的128位散列值(32個字符)。這篇文...

    LYSNote5432021-02-04
  • IOSiOS開發技巧之狀態欄字體顏色的設置方法

    iOS開發技巧之狀態欄字體顏色的設置方法

    有時候我們需要根據不同的背景修改狀態欄字體的顏色,下面這篇文章主要給大家介紹了關于iOS開發技巧之狀態欄字體顏色的設置方法,文中通過示例代碼...

    夢想家-mxj8922021-05-10
  • IOSiOS開發之視圖切換

    iOS開發之視圖切換

    在iOS開發中視圖的切換是很頻繁的,獨立的視圖應用在實際開發過程中并不常見,除非你的應用足夠簡單。在iOS開發中常用的視圖切換有三種,今天我們將...

    執著丶執念5272021-01-16
  • IOSiOS中UILabel實現長按復制功能實例代碼

    iOS中UILabel實現長按復制功能實例代碼

    在iOS開發過程中,有時候會用到UILabel展示的內容,那么就設計到點擊UILabel復制它上面展示的內容的功能,也就是Label長按復制功能,下面這篇文章主要給大...

    devilx12792021-04-02
  • IOSiOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    這篇文章主要介紹了iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果的相關資料,需要的朋友可以參考下...

    jiangamh8882021-01-11
  • IOS詳解iOS中多個網絡請求的同步問題總結

    詳解iOS中多個網絡請求的同步問題總結

    這篇文章主要介紹了詳解iOS中多個網絡請求的同步問題總結,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧...

    liang199111302021-03-15
  • IOSiOS實現控制屏幕常亮不變暗的方法示例

    iOS實現控制屏幕常亮不變暗的方法示例

    最近在工作中遇到了要將iOS屏幕保持常亮的需求,所以下面這篇文章主要給大家介紹了關于利用iOS如何實現控制屏幕常亮不變暗的方法,文中給出了詳細的...

    隨風13332021-04-02
  • IOSiOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)

    iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和

    這篇文章主要介紹了iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)的相關資料,需要的朋友可以參考下...

    CodingFire13652021-02-26
主站蜘蛛池模板: 色婷婷基地 | 久久久久久久久国产 | 欧美午夜在线 | 日韩中文字幕av | 黄网页在线观看 | 亚洲精品久久久久久国产精华液 | 国产精品自在线 | 国产一卡二卡三卡 | 成人片免费看 | 国产精品国产三级国产aⅴ原创 | 亚洲免费成人在线 | 中文字幕在线精品 | 伊人草| 中文字幕91 | 日韩欧美综合 | 欧美一区二区三区久久久久久桃花 | 欧美一区在线看 | 国产99久久精品一区二区永久免费 | 国产一区二区三区播放 | 激情小视频 | www.av欧美| 亚洲国产精品一区 | 亚洲乱码国产乱码精品精的特点 | 国产欧美自拍 | 亚洲高清在线 | 久久免费精品视频 | 欧美另类综合 | 含羞草www网址进入在线观看 | 欧美综合一区二区三区 | 国产精品美女久久久久久免费 | 久久国产精品久久久久久 | 在线观看av网站永久 | 国产精品久久国产精品 | 欧美视频网站 | 精品人成 | 欧洲一级毛片 | 九九色综合 | 亚洲午夜精品 | av色综合 | 91国产视频在线 | 日本一区二区不卡在线观看 |