|
|
@@ -61,17 +61,18 @@
|
|
|
self.navigationController.navigationBarHidden = YES;
|
|
|
|
|
|
// 掩藏滚动
|
|
|
- [self.view insertSubview:self.mask belowSubview:self.indicator];
|
|
|
+// [self.view insertSubview:self.mask belowSubview:self.indicator];
|
|
|
}
|
|
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
|
|
|
|
- if (self.currentIndex > 0) {
|
|
|
- [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
|
|
|
- }
|
|
|
+// if (self.currentIndex > 0) {
|
|
|
+// [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
|
|
|
+// }
|
|
|
|
|
|
+ [self scrollToIndex:self.currentIndex + 1];
|
|
|
}
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
@@ -79,14 +80,14 @@
|
|
|
|
|
|
// [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
|
|
|
|
|
|
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
- sleep(0.25);
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [self.mask removeFromSuperview];
|
|
|
- self.mask = nil;
|
|
|
- });
|
|
|
-
|
|
|
- });
|
|
|
+// dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+// sleep(0.25);
|
|
|
+// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+// [self.mask removeFromSuperview];
|
|
|
+// self.mask = nil;
|
|
|
+// });
|
|
|
+//
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
|
@@ -95,8 +96,12 @@
|
|
|
[self.previewContainer.collectionViewLayout invalidateLayout];
|
|
|
|
|
|
// 重新布局Item位置
|
|
|
- [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:32 animated:NO];
|
|
|
-
|
|
|
+// [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:32 animated:NO];
|
|
|
+ [self scrollToIndex:self.currentIndex + 1];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)prefersStatusBarHidden {
|
|
|
+ return YES;
|
|
|
}
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
@@ -116,7 +121,7 @@
|
|
|
#pragma mark - Setter
|
|
|
|
|
|
- (void)setOffset:(NSUInteger)offset {
|
|
|
- [self setCurrentIndex:offset + 1];
|
|
|
+ [self setCurrentIndex:offset];
|
|
|
}
|
|
|
|
|
|
//- (void)setCurrentIndex:(NSUInteger)currentIndex {
|
|
|
@@ -149,7 +154,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
- NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
|
+ NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
|
|
|
+ NSDictionary *item = [self.photos objectAtIndex:idx];
|
|
|
NSString *type = [item objectForKey:@"type"];
|
|
|
|
|
|
if ([type isEqualToString:@"image"]) {
|
|
|
@@ -170,7 +176,8 @@
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
- NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
|
+ NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
|
|
|
+ NSDictionary *item = [self.photos objectAtIndex:idx];
|
|
|
NSString *type = [item objectForKey:@"type"];
|
|
|
|
|
|
if ([type isEqualToString:@"image"]) {
|
|
|
@@ -188,7 +195,9 @@
|
|
|
}
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
|
+
|
|
|
+ NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
|
|
|
+ NSDictionary *item = [self.photos objectAtIndex:idx];
|
|
|
NSString *type = [item objectForKey:@"type"];
|
|
|
|
|
|
if ([type isEqualToString:@"video"]) {
|
|
|
@@ -203,12 +212,14 @@
|
|
|
#pragma mark - CollectionView DataSource
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
- return self.photos.count;
|
|
|
+ return self.photos.count + 2;
|
|
|
}
|
|
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
- NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
|
+ NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
|
|
|
+
|
|
|
+ NSDictionary *item = [self.photos objectAtIndex:idx];
|
|
|
NSString *type = [item objectForKey:@"type"];
|
|
|
|
|
|
if ([type isEqualToString:@"image"]) {
|
|
|
@@ -230,17 +241,47 @@
|
|
|
#pragma mark - ScrollView Delegate
|
|
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
|
- if (scrollView == self.previewContainer) {
|
|
|
+// if (scrollView == self.previewContainer) {
|
|
|
+//
|
|
|
+// CGFloat x = scrollView.contentOffset.x / scrollView.frame.size.width;
|
|
|
+// int idx = (int)x;
|
|
|
+// if (idx == x) {
|
|
|
+// if (self.currentIndex != idx) {
|
|
|
+// self.currentIndex = idx;
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+}
|
|
|
|
|
|
- CGFloat x = scrollView.contentOffset.x / scrollView.frame.size.width;
|
|
|
- int idx = (int)x;
|
|
|
- if (idx == x) {
|
|
|
- if (self.currentIndex != idx) {
|
|
|
- self.currentIndex = idx;
|
|
|
-
|
|
|
- }
|
|
|
+- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
|
|
+ CGFloat offsetX = scrollView.contentOffset.x;
|
|
|
+ float idxf = offsetX / CGRectGetWidth(scrollView.frame);
|
|
|
+ int idxi = (int)(offsetX / CGRectGetWidth(scrollView.frame));
|
|
|
+
|
|
|
+ if (idxf == idxi) {
|
|
|
+ if (idxi == 0) {
|
|
|
+ self.currentIndex = self.photos.count - 1;
|
|
|
+ } else if (idxi == self.photos.count + 1) {
|
|
|
+ self.currentIndex = 0;
|
|
|
+ } else {
|
|
|
+ self.currentIndex = idxi - 1;
|
|
|
}
|
|
|
+
|
|
|
+// if (self.indicator) {
|
|
|
+// self.indicator(self.currentIndex, self.photos.count);
|
|
|
+// }
|
|
|
+ [self updateIndicator];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (idxi == 0) {
|
|
|
+ [self scrollToIndex:self.photos.count];
|
|
|
}
|
|
|
+
|
|
|
+ if (idxi == self.photos.count + 1) {
|
|
|
+ [self scrollToIndex:1];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
|
|
|
@@ -260,6 +301,11 @@
|
|
|
|
|
|
#pragma mark - Private
|
|
|
|
|
|
+- (void)updateIndicator {
|
|
|
+ NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
|
|
|
+ self.indicator.text = offset;
|
|
|
+}
|
|
|
+
|
|
|
- (NSUInteger)contentOffsetForIndexPath:(NSIndexPath *)indexPath {
|
|
|
NSUInteger idx = indexPath.row;
|
|
|
if (idx == 0) {
|
|
|
@@ -272,6 +318,10 @@
|
|
|
return idx;
|
|
|
}
|
|
|
|
|
|
+- (void)scrollToIndex:(NSUInteger)index { // 不会出现肉眼可见的滚动效果
|
|
|
+ self.previewContainer.contentOffset = CGPointMake(index * CGRectGetWidth(self.previewContainer.frame), 0);
|
|
|
+}
|
|
|
+
|
|
|
- (void) photoCell:(PhotoPreviewCell *)cell loadImage:(NSDictionary *)item_json {
|
|
|
|
|
|
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|