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

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

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

服務(wù)器之家 - 編程語言 - IOS - IOS 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)

IOS 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)

2021-03-29 15:10水桶前輩 IOS

這篇文章主要介紹了IOS 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)的相關(guān)資料,希望通過此文大家能夠掌握輪播圖的實(shí)現(xiàn),需要的朋友可以參考下

IOS 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)

截圖

IOS 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)

1.使用

?
1
2
3
4
LJPhotoGroupView *_ljPhotoGroupView = [[LJPhotoGroupView alloc]initWithItem:self.ljUrlArray];
_ljPhotoGroupView.backgroundColor = [UIColor blackColor];
_ljPhotoGroupView.frame = CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT);
[_ljPhotoGroupView showHintView:self];

2.源碼

?
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#import "LJPhotoGroupView.h"
#import "LJWebIDataManager.h"
 
@interface LJPhotoGroupCellView()
 
@property (nonatomic, strong) UIImageView *ljImageview;
 
@end
 
@implementation LJPhotoGroupCellView
 
- (instancetype)initWithFrame:(CGRect)frame url:(NSString*)imageurl
{
  self = [super initWithFrame:frame];
  if (self) {
    [self addSubview:self.ljImageview];
    //這里大家可以換成自己的網(wǎng)絡(luò)請求圖片的方法
    [[LJWebIDataManager sharedInstances]retrieveData:imageurl successBlock:^(NSData *netData, NSString *progressStr, BOOL isFinished) {
      //在主線程中刷新界面
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 
        UIImage *_ljImage = [UIImage imageWithData: netData scale:0.3];
        @myWeakify(self);
        dispatch_async(dispatch_get_main_queue(), ^{
          @myStrongify(self);
          self.ljImageview.image = _ljImage;
        });
      });
    }];
  }
  return self;
}
 
- (UIImageView*)ljImageview
{
  if (!_ljImageview) {
    _ljImageview = UIImageView.new;
    _ljImageview.frame = CGRectMake(15, 0, kDEVICEWIDTH - 30, 130);
    _ljImageview.backgroundColor = [UIColor redColor];
    UIGestureRecognizer *_tap = [[UIGestureRecognizer alloc]initWithTarget:self action:@selector(dismissHintView)];
    [_ljImageview addGestureRecognizer:_tap];
  }
  return _ljImageview;
}
 
@end
 
@interface LJPhotoGroupView()<UIScrollViewDelegate>
 
@property (nonatomic, strong) UIScrollView *ljScrollView;
@property (nonatomic, strong) NSArray *ljItemArray;
@property (nonatomic, strong) UIImageView *ljImageview;
@property (nonatomic, strong) UIPageControl *ljPageControl;
 
 
@end
 
@implementation LJPhotoGroupView
 
- (instancetype)initWithItem:(NSArray*)ljArray
{
  self = [super init];
  if (self)
  {
    self.ljItemArray = [NSArray arrayWithArray:ljArray];
     
    [self addSubview:self.ljScrollView];
    [self addSubview:self.ljPageControl];
     
    for (int i = 0; i < self.ljItemArray.count; i++) {
       
      //方法一:直接設(shè)置每個cell的X坐標(biāo)
//      LJPhotoGroupCellView *_cell = [[LJPhotoGroupCellView alloc]initWithFrame:CGRectMake((kDEVICEWIDTH )*i, 0, kDEVICEWIDTH, 130) url:self.ljItemArray[i]];
       
      //方法二:先不用考慮cell的X坐標(biāo),在下面設(shè)置X的坐標(biāo)
      LJPhotoGroupCellView *cell = [[LJPhotoGroupCellView alloc]initWithFrame:self.ljScrollView.bounds url:self.ljItemArray[i]];
      UITapGestureRecognizer *_tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissHintView)];
        [cell addGestureRecognizer:_tap];
      [self.ljScrollView addSubview:cell];
    }
     
    //方法二:設(shè)置cell的X坐標(biāo)
    // 計(jì)算imageView的位置
    [self.ljScrollView.subviews enumerateObjectsUsingBlock:^(LJPhotoGroupCellView *cell, NSUInteger idx, BOOL *stop)
     {
      // 調(diào)整x => origin => frame
      CGRect frame = cell.frame;
      frame.origin.x = idx * frame.size.width;
       
      cell.frame = frame;
    }];
     
    self.ljPageControl.currentPage = 0;
  }
  return self;
}
 
- (UIScrollView*)ljScrollView
{
  if (!_ljScrollView)
  {
    _ljScrollView = UIScrollView.new;
    _ljScrollView.frame = CGRectMake(0, 250, kDEVICEWIDTH, 130);
    _ljScrollView.delegate = self;
    //_scrollView.scrollsToTop = NO;
    _ljScrollView.pagingEnabled = YES;
    _ljScrollView.contentSize = CGSizeMake(_ljScrollView.bounds.size.width * self.ljItemArray.count, 130);
    //_scrollView.alwaysBounceHorizontal = groupItems.count > 1;
    // _scrollView.showsHorizontalScrollIndicator = NO;
    //_scrollView.showsVerticalScrollIndicator = NO;
    //_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    //_scrollView.delaysContentTouches = NO;
    //_scrollView.canCancelContentTouches = YES;
  }
  return _ljScrollView;
}
 
- (UIPageControl *)ljPageControl
{
  if (_ljPageControl == nil)
  {
    // 分頁控件,本質(zhì)上和scrollView沒有任何關(guān)系,是兩個獨(dú)立的控件
    _ljPageControl = [[UIPageControl alloc] init];
    // 總頁數(shù)
    _ljPageControl.numberOfPages = self.ljItemArray.count;
    CGSize size = [_ljPageControl sizeForNumberOfPages:self.ljItemArray.count];
     
    _ljPageControl.bounds = CGRectMake(0, 0, size.width, size.height);
    _ljPageControl.center = CGPointMake(self.center.x, 380);
     
    // 設(shè)置顏色
    _ljPageControl.pageIndicatorTintColor = [UIColor redColor];
    //當(dāng)前頁面的顏色
    _ljPageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    [_ljPageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
  }
  return _ljPageControl;
}
 
// 分頁控件的監(jiān)聽方法
- (void)pageChanged:(UIPageControl *)page
{
  NSLog(@"%ld", (long)page.currentPage);
   
  // 根據(jù)頁數(shù),調(diào)整滾動視圖中的圖片位置 contentOffset self.scrollView.bounds.size.width
  CGFloat x = page.currentPage * (kDEVICEWIDTH);
  [self.ljScrollView setContentOffset:CGPointMake(x, 0) animated:YES];
}
 
- (UIImageView*)ljImageview
{
  if (!_ljImageview) {
    _ljImageview = UIImageView.new;
    _ljImageview.frame = CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT);
    _ljImageview.backgroundColor = [UIColor redColor];
     
    UIGestureRecognizer *_tap = [[UIGestureRecognizer alloc]initWithTarget:self action:@selector(dismissHintView)];
    [_ljImageview addGestureRecognizer:_tap];
  }
  return _ljImageview;
}
 
 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  //CGFloat floatPage = _scrollView.contentOffset.x / _scrollView.width;
  //NSInteger page = _scrollView.contentOffset.x / _scrollView.width;
}
 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  if (!decelerate) {
  }
}
 
 
#pragma mark - ScrollView的代理方法
// 滾動視圖停下來,修改頁面控件的小點(diǎn)(頁數(shù))
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
  // 停下來的當(dāng)前頁數(shù)
  NSLog(@"%@", NSStringFromCGPoint(scrollView.contentOffset));
   
  // 計(jì)算頁數(shù)
  int page = scrollView.contentOffset.x / scrollView.bounds.size.width;
   
  self.ljPageControl.currentPage = page;
}
 
 
- (void)showHintView:(UIView*)view
{
  //[view addSubview:self];
   [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:self];
   
  self.alpha = 0.0;
  [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
     
    self.alpha = 1.0;
     
  } completion:^(BOOL finished)
   {
      
   }];
}
 
- (void)dismissHintView
{
  [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
     
    self.alpha = 0.0;
     
  } completion:^(BOOL finished){
     
    [self removeFromSuperview];
  }];
}
 
@end

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

原文鏈接:http://blog.csdn.net/robinson_911/article/details/76038882

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产精品久久久爽爽爽麻豆色哟哟 | 亚洲美女网址 | 欧美片网站免费 | wwwav在线 | 99久久婷婷国产综合精品电影 | 久久精品小视频 | 自拍视频网| 国内久久精品 | 美女操av | 免费久久99精品国产婷婷六月 | 精品国产乱码久久久久久影片 | 一二区视频 | 亚洲视频在线观看视频 | 欧美日韩国产一区二区三区 | 亚洲男人天堂2023 | 欧美一级黄色片 | 亚洲一区视频在线 | 免费在线黄色电影 | 久久这里只有精品免费 | 在线一级片 | 日本在线小视频 | 激情欧美日韩一区二区 | 亚洲精品久久久久久一区二区 | 中文字幕免费播放 | 亚洲久久久久久 | 久久亚洲欧美日韩精品专区 | 一区二区三区高清 | 成人午夜精品一区二区三区 | 透逼视频 | 二区在线视频 | 久久久91精品国产一区二区三区 | 免费观看黄视频 | 日本不卡一区二区三区在线观看 | 国产一区av在线 | 福利片一区二区 | 大毛片 | 成人精品网站在线观看 | 91精品国产视频 | 视频在线一区 | 国产欧美一区二区视频 | 寡妇少妇高潮免费看蜜臀a 午夜免费电影 |