Skip to content

Commit 8ca6db4

Browse files
committed
去掉商城banner 改成滑动
1 parent f01e7b8 commit 8ca6db4

5 files changed

Lines changed: 189 additions & 131 deletions

File tree

Coding_iOS/Controllers/Shop/ShopOrderViewController.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,24 @@ - (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel{
124124
listView.myOrder = _myOrder;
125125
[listView reloadData];
126126

127+
EaseBlankPageType _orderEmptyType;
128+
if (_myOrder.orderType == ShopOrderSend)
129+
{
130+
_orderEmptyType = EaseBlankPageTypeShopSendOrders;
131+
}else if (_myOrder.orderType == ShopOrderUnSend)
132+
{
133+
_orderEmptyType = EaseBlankPageTypeShopUnSendOrders;
134+
}else
135+
_orderEmptyType = EaseBlankPageTypeShopOrders;
136+
137+
[listView configBlankPage:_orderEmptyType hasData:( [_myOrder getDataSourceByOrderType].count > 0) hasError:NO reloadButtonBlock:^(id sender) {
138+
}];
139+
127140
if (_mySegmentControl) {
128141
_mySegmentControl.currentIndex = carousel.currentItemIndex;
129142
}
143+
144+
130145
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
131146
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
132147
}];

Coding_iOS/Controllers/Shop/ShopViewController.m

Lines changed: 168 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,39 @@
1616

1717
#import "Shop.h"
1818
#import "ShopBanner.h"
19+
#import "iCarousel.h"
20+
@class ShopListView;
1921

2022
#import "Coding_NetAPIManager.h"
2123
#import "UIScrollView+SVInfiniteScrolling.h"
2224

23-
@interface ShopViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
25+
@protocol ShopListViewDelegate <NSObject>
26+
27+
- (void)didSelectGoodItem:(ShopGoods *)good;
28+
29+
@end
30+
31+
@interface ShopListView : UIView
32+
33+
@property(nonatomic, weak)id<ShopListViewDelegate> delegate;
34+
@property(nonatomic,strong)NSArray *dataSource;
35+
36+
@end
37+
38+
39+
@interface ShopViewController ()<iCarouselDataSource,iCarouselDelegate,ShopListViewDelegate>
2440
{
25-
UICollectionView *_collectionView;
2641
UIView *_collectionHeaderView;
27-
2842
XTSegmentControl *_shopSegmentControl;
2943
ShopBannerView *_shopBannerView;
3044

3145
NSInteger _oldSelectedIndex;
3246
BOOL _isRequest;
3347
}
3448

35-
@property(nonatomic,strong)XTSegmentControl *shopSegmentControl;
36-
@property(nonatomic,strong)UICollectionView *collectionView;
49+
@property (strong, nonatomic) XTSegmentControl *mySegmentControl;
50+
@property (strong, nonatomic) NSArray *titlesArray;
51+
@property (strong, nonatomic) iCarousel *myCarousel;
3752
@property(nonatomic,strong)Shop *shopObject;
3853

3954
@end
@@ -64,6 +79,18 @@ - (void)bannerClicked:(NSString *)linkStr{
6479
}
6580
}
6681

82+
#pragma mark---------------------- ShopListViewDelegate --------------------
83+
- (void)didSelectGoodItem:(ShopGoods *)model
84+
{
85+
if (!model.exchangeable) {
86+
[NSObject showHudTipStr:@"您的码币余额不足,不能兑换该商品"];
87+
return;
88+
}
89+
ExchangeGoodsViewController *exChangeViewController = [[ExchangeGoodsViewController alloc] init];
90+
exChangeViewController.shopGoods = model;
91+
[self.navigationController pushViewController:exChangeViewController animated:YES];
92+
}
93+
6794

6895
#pragma mark-
6996
#pragma mark---------------------- ControllerLife ---------------------------
@@ -74,9 +101,8 @@ - (void)viewDidLoad {
74101
self.title = @"我的商城";
75102
_shopObject = [[Shop alloc] init];
76103
_shopObject.shopType = ShopTypeAll;
77-
78-
[self setUpCollectionView];
79-
[self setUpSegmentControl];
104+
105+
[self setUpView];
80106

81107
// 一次性加载所有数据,暂时没有做分页的需要,先注释.
82108
// __weak typeof(self) weakSelf = self;
@@ -113,10 +139,9 @@ - (void)requestgiftsList {
113139

114140
[self.view beginLoading];
115141
__weak typeof(self) weakSelf = self;
116-
[[Coding_NetAPIManager sharedManager] request_shop_bannersWithBlock:^(id data, NSError *error) {
117-
weakSelf.shopObject.shopBannerArray = data;
118-
[weakSelf.collectionView reloadData];
119-
}];
142+
// [[Coding_NetAPIManager sharedManager] request_shop_bannersWithBlock:^(id data, NSError *error) {
143+
// weakSelf.shopObject.shopBannerArray = data;
144+
// }];
120145

121146
[[Coding_NetAPIManager sharedManager] request_shop_userPointWithShop:_shopObject andBlock:^(id data, NSError *error) {
122147
if (data) {
@@ -131,147 +156,182 @@ - (void)loadGiftsList
131156
[[Coding_NetAPIManager sharedManager] request_shop_giftsWithShop:_shopObject andBlock:^(id data, NSError *error) {
132157
[weakSelf.view endLoading];
133158
if (data) {
134-
[weakSelf.collectionView reloadData];
159+
ShopListView *listView = (ShopListView *)[weakSelf.myCarousel currentItemView];
160+
listView.dataSource = weakSelf.shopObject.dateSource;
135161
}else
136162
[NSObject showHudTipStr:@"Error"];
137163
}];
138164
}
139165

140166

141-
#pragma mark-
142-
#pragma mark---------------------- initView ---------------------------
167+
- (void)setUpView
168+
{
169+
//添加myCarousel
170+
self.myCarousel = ({
171+
iCarousel *icarousel = [[iCarousel alloc] initWithFrame:CGRectZero];
172+
icarousel.dataSource = self;
173+
icarousel.delegate = self;
174+
icarousel.decelerationRate = 1.0;
175+
icarousel.scrollSpeed = 1.0;
176+
icarousel.type = iCarouselTypeLinear;
177+
icarousel.pagingEnabled = YES;
178+
icarousel.clipsToBounds = YES;
179+
icarousel.bounceDistance = 0.2;
180+
[self.view addSubview:icarousel];
181+
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
182+
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(kMySegmentControl_Height, 0, 0, 0));
183+
}];
184+
185+
icarousel;
186+
});
187+
__weak typeof(self) weakSelf = self;
188+
self.mySegmentControl = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kMySegmentControl_Height) Items:self.titlesArray selectedBlock:^(NSInteger index) {
189+
[weakSelf.myCarousel scrollToItemAtIndex:index animated:NO];
190+
}];
191+
[self.view addSubview:self.mySegmentControl];
192+
}
193+
194+
#pragma mark - Getter/Setter
195+
- (NSArray*)titlesArray
196+
{
197+
if (nil == _titlesArray) {
198+
_titlesArray = @[@"全部商品", @"可兑换商品"];
199+
}
200+
return _titlesArray;
201+
}
202+
#pragma mark iCarousel M
203+
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
204+
return [self.titlesArray count];
205+
}
206+
207+
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
208+
209+
ShopListView *listView = (ShopListView *)view;
210+
if (listView) {
211+
212+
}else{
213+
listView = [[ShopListView alloc] initWithFrame:carousel.bounds];
214+
}
215+
listView.delegate = self;
216+
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
217+
return listView;
218+
}
219+
220+
- (void)carouselDidScroll:(iCarousel *)carousel{
221+
if (_mySegmentControl) {
222+
float offset = carousel.scrollOffset;
223+
if (offset > 0) {
224+
[_mySegmentControl moveIndexWithProgress:offset];
225+
}
226+
}
227+
}
228+
229+
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel{
230+
231+
ShopListView *listView = (ShopListView *)carousel.currentItemView;
232+
if (_mySegmentControl) {
233+
_mySegmentControl.currentIndex = carousel.currentItemIndex;
234+
}
235+
236+
if (carousel.currentItemIndex == 0) {
237+
listView.dataSource = _shopObject.dateSource;
238+
239+
}else if(carousel.currentItemIndex == 1)
240+
{
241+
listView.dataSource = [_shopObject getExchangeGiftData];
242+
}
243+
244+
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
245+
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
246+
}];
247+
}
248+
249+
- (void)didReceiveMemoryWarning {
250+
[super didReceiveMemoryWarning];
251+
// Dispose of any resources that can be recreated.
252+
}
253+
- (void)dealloc
254+
{
255+
_myCarousel.delegate = nil;
256+
_myCarousel.dataSource = nil;
257+
}
258+
259+
@end
260+
261+
262+
@interface ShopListView () <UICollectionViewDataSource,UICollectionViewDelegate>
263+
{
264+
UICollectionView *_collectionView;
265+
}
266+
267+
@end
268+
269+
@implementation ShopListView
270+
271+
- (instancetype)initWithFrame:(CGRect)frame
272+
{
273+
self = [super initWithFrame:frame];
274+
if (self) {
275+
276+
[self setUpCollectionView];
277+
}
278+
return self;
279+
}
143280

144281
- (void)setUpCollectionView
145282
{
146283
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
147-
CGFloat itemW = (self.view.frame.size.width - 12 * 3) / 2;
284+
CGFloat itemW = (kScreen_Width - 12 * 3) / 2;
148285
CGFloat itemH = itemW * (175.0/284.0) + 10 +21 +5 +13 +5;
149-
286+
150287
layout.itemSize = CGSizeMake(itemW, itemH);
288+
layout.sectionInset = UIEdgeInsetsMake(20, 12, 20, 12);
151289
layout.minimumInteritemSpacing = 5;
152290
layout.minimumLineSpacing = 20;
153-
154-
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) collectionViewLayout:layout];
291+
292+
_collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
155293
_collectionView.backgroundColor = [UIColor clearColor];
156294

157295
[_collectionView registerClass:[ShopGoodsCCell class] forCellWithReuseIdentifier:@"TopicProductCollectionCellIdentifier"];
158296
_collectionView.dataSource = self;
159297
_collectionView.delegate = self;
160298
_collectionView.layer.masksToBounds = NO;
161-
[self.view addSubview:_collectionView];
162-
163-
CGFloat bannerHeight = kMySegmentControl_Height;
164-
_collectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _collectionView.frame.size.width, bannerHeight)];
165-
_collectionHeaderView.backgroundColor = [UIColor whiteColor];
166-
[_collectionView addSubview:_collectionHeaderView];
167-
299+
[self addSubview:_collectionView];
168300
}
169301

170-
- (void)setUpSegmentControl
302+
- (void)setDataSource:(NSArray *)dataSource
171303
{
172-
//添加滑块
173-
NSArray *_segmentItems = @[@"全部商品",@"可兑换商品"];
174-
__weak typeof(self) weakSelf = self;
175-
_shopSegmentControl = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(_collectionHeaderView.frame)- kMySegmentControl_Height - 5, kScreen_Width, kMySegmentControl_Height) Items:_segmentItems selectedBlock:^(NSInteger index) {
176-
177-
[weakSelf segmentControlSelecteIndex:index];
178-
}];
179-
_shopSegmentControl.backgroundColor = [UIColor whiteColor];
180-
[_collectionHeaderView addSubview:_shopSegmentControl];
181-
[self.view bringSubviewToFront:_shopSegmentControl];
182-
}
183-
184-
- (void)segmentControlSelecteIndex:(NSInteger)index
185-
{
186-
if (index == _oldSelectedIndex) {
187-
return;
188-
}
189-
_oldSelectedIndex = index;
190-
_shopObject.shopType = index;
304+
_dataSource = dataSource;
191305
[_collectionView reloadData];
306+
307+
[self configBlankPage:EaseBlankPageTypeNoExchangeGoods hasData:_dataSource.count > 0 hasError:NO reloadButtonBlock:^(id sender) {
308+
}];
192309
}
193310

194-
195311
#pragma mark - UICollectionViewDataSource
196312

197313
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
198314
{
199-
return _shopObject.dateSource.count;
315+
return _dataSource.count;
200316
}
201317

202318
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
203319
{
204320
ShopGoodsCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TopicProductCollectionCellIdentifier" forIndexPath:indexPath];
205-
BaseModel *model = _shopObject.dateSource[indexPath.row];
321+
BaseModel *model = _dataSource[indexPath.row];
206322
[cell configViewWithModel:model];
207323

208324
return cell;
209325
}
210326

211-
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
212-
{
213-
CGFloat height = kMySegmentControl_Height;
214-
NSArray * shopBannerArray = _shopObject.shopBannerArray;
215-
if ( shopBannerArray && shopBannerArray.count > 0) {
216-
217-
CGFloat bannerHeight = kScreen_Width * (270.0/640);
218-
_shopBannerView = [[ShopBannerView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, bannerHeight)];
219-
_shopBannerView.curBannerList = shopBannerArray;
220-
[_collectionHeaderView addSubview:_shopBannerView];
221-
[_shopBannerView reloadData];
222-
_shopSegmentControl.frame = CGRectMake(0, bannerHeight, kScreen_Width, kMySegmentControl_Height);
223-
height = kMySegmentControl_Height + bannerHeight ;
224-
_collectionHeaderView.frame = CGRectMake(0, 0, kScreen_Width, height);
225-
}
226-
return UIEdgeInsetsMake(20 + height, 10, 10, 10);
227-
}
228327

229328
#pragma mark - UICollectionViewDelegate
230329

231330
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
232331
{
233-
ShopGoods *model = _shopObject.dateSource[indexPath.row];
234-
if (!model.exchangeable) {
235-
[NSObject showHudTipStr:@"您的码币余额不足,不能兑换该商品"];
236-
return;
332+
ShopGoods *model = _dataSource[indexPath.row];
333+
if (_delegate && [_delegate respondsToSelector:@selector(didSelectGoodItem:)]) {
334+
[_delegate didSelectGoodItem:model];
237335
}
238-
ExchangeGoodsViewController *exChangeViewController = [[ExchangeGoodsViewController alloc] init];
239-
exChangeViewController.shopGoods = model;
240-
[self.navigationController pushViewController:exChangeViewController animated:YES];
241-
// [BaseViewController presentVC:exChangeViewController];
242-
243336
}
244-
245-
246-
#pragma mark - UIScrollViewDelegate
247-
248-
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
249-
{
250-
CGFloat offsetY = scrollView.contentOffset.y + scrollView.contentInset.top;
251-
CGFloat bannerHeight = kScreen_Width * (270.0/640);
252-
253-
NSLog(@"%f%f",offsetY,CGRectGetHeight(_collectionHeaderView.frame));
254-
255-
if (offsetY >= CGRectGetHeight(_collectionHeaderView.frame) -kMySegmentControl_Height ) {
256-
257-
_shopSegmentControl.frame = CGRectMake(0, 0, kScreen_Width, kMySegmentControl_Height);
258-
[self.view addSubview:_shopSegmentControl];
259-
}else
260-
{
261-
_shopSegmentControl.frame = CGRectMake(0,bannerHeight, kScreen_Width, kMySegmentControl_Height);
262-
[_collectionHeaderView addSubview:_shopSegmentControl];
263-
}
264-
}
265-
266-
267-
- (void)didReceiveMemoryWarning {
268-
[super didReceiveMemoryWarning];
269-
// Dispose of any resources that can be recreated.
270-
}
271-
- (void)dealloc
272-
{
273-
_collectionView.delegate = nil;
274-
_collectionView.dataSource = nil;
275-
}
276-
277337
@end

0 commit comments

Comments
 (0)