|
@@ -16,12 +16,13 @@
|
|
|
|
|
|
|
|
@interface ContentPreviewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
@interface ContentPreviewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
|
|
|
|
|
|
|
|
+@property (nonatomic,assign) NSUInteger currentIndex;
|
|
|
@property (strong, nonatomic) IBOutlet UILabel *indicator;
|
|
@property (strong, nonatomic) IBOutlet UILabel *indicator;
|
|
|
@property (strong, nonatomic) IBOutlet UICollectionView *previewContainer;
|
|
@property (strong, nonatomic) IBOutlet UICollectionView *previewContainer;
|
|
|
|
|
|
|
|
@property (nonatomic,strong) NSArray *photos;
|
|
@property (nonatomic,strong) NSArray *photos;
|
|
|
|
|
|
|
|
-@property (nonatomic,strong) UIScrollView *mask;
|
|
|
|
|
|
|
+@property (nonatomic,strong) UIView *mask;
|
|
|
|
|
|
|
|
@property (nonatomic,assign) BOOL hideNavigationBar;
|
|
@property (nonatomic,assign) BOOL hideNavigationBar;
|
|
|
|
|
|
|
@@ -59,6 +60,8 @@
|
|
|
|
|
|
|
|
self.navigationController.navigationBarHidden = YES;
|
|
self.navigationController.navigationBarHidden = YES;
|
|
|
|
|
|
|
|
|
|
+ // 掩藏滚动
|
|
|
|
|
+ [self.view insertSubview:self.mask belowSubview:self.indicator];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
- (void)viewDidLayoutSubviews {
|
|
@@ -73,6 +76,17 @@
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
[super viewDidAppear:animated];
|
|
[super viewDidAppear:animated];
|
|
|
|
|
+
|
|
|
|
|
+// [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;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
@@ -90,15 +104,27 @@
|
|
|
// Dispose of any resources that can be recreated.
|
|
// Dispose of any resources that can be recreated.
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+- (UIView *)mask {
|
|
|
|
|
+ if (!_mask) {
|
|
|
|
|
+ _mask = [[UIView alloc] initWithFrame:self.view.bounds];
|
|
|
|
|
+ _mask.backgroundColor = [UIColor blackColor];
|
|
|
|
|
+ }
|
|
|
|
|
+ return _mask;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
#pragma mark - Setter
|
|
#pragma mark - Setter
|
|
|
|
|
|
|
|
-- (void)setCurrentIndex:(NSUInteger)currentIndex {
|
|
|
|
|
- _currentIndex = currentIndex;
|
|
|
|
|
- NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
|
|
|
|
|
- self.indicator.text = offset;
|
|
|
|
|
|
|
+- (void)setOffset:(NSUInteger)offset {
|
|
|
|
|
+ [self setCurrentIndex:offset + 1];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+//- (void)setCurrentIndex:(NSUInteger)currentIndex {
|
|
|
|
|
+// _currentIndex = currentIndex;
|
|
|
|
|
+// NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
|
|
|
|
|
+// self.indicator.text = offset;
|
|
|
|
|
+//}
|
|
|
|
|
+
|
|
|
#pragma mark - FlowLayout Delegate
|
|
#pragma mark - FlowLayout Delegate
|
|
|
|
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
@@ -122,6 +148,7 @@
|
|
|
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
|
NSString *type = [item objectForKey:@"type"];
|
|
NSString *type = [item objectForKey:@"type"];
|
|
|
|
|
|
|
@@ -130,13 +157,13 @@
|
|
|
|
|
|
|
|
[self photoCell:preCell loadImage:item];
|
|
[self photoCell:preCell loadImage:item];
|
|
|
|
|
|
|
|
-// preCell.scrollView.backgroundColor = [UIColor colorWithRed:(rand() % 255) / 255.0 green:(rand() % 255) / 255.0 blue:(rand() % 255) / 255.0 alpha:1];
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
} else if ([type isEqualToString:@"video"]) {
|
|
} else if ([type isEqualToString:@"video"]) {
|
|
|
|
|
|
|
|
VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
|
|
VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
|
|
|
videoCell.item = item;
|
|
videoCell.item = item;
|
|
|
-// videoCell.playerView.webView.backgroundColor = [UIColor colorWithRed:(rand() % 255) / 255.0 green:(rand() % 255) / 255.0 blue:(rand() % 255) / 255.0 alpha:1];
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -156,7 +183,19 @@
|
|
|
|
|
|
|
|
VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
|
|
VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
|
|
|
|
|
|
|
|
- [videoCell.playerView pauseVideo];
|
|
|
|
|
|
|
+ [videoCell reset];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
+ NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
|
|
|
|
|
+ NSString *type = [item objectForKey:@"type"];
|
|
|
|
|
+
|
|
|
|
|
+ if ([type isEqualToString:@"video"]) {
|
|
|
|
|
+
|
|
|
|
|
+ VideoPreviewCell *videoCell = (VideoPreviewCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
|
|
|
|
+
|
|
|
|
|
+ [videoCell play];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -181,7 +220,7 @@
|
|
|
} else if ([type isEqualToString:@"video"]) {
|
|
} else if ([type isEqualToString:@"video"]) {
|
|
|
|
|
|
|
|
VideoPreviewCell *videoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoPreviewCell" forIndexPath:indexPath];
|
|
VideoPreviewCell *videoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoPreviewCell" forIndexPath:indexPath];
|
|
|
- videoCell.playerView.webView.backgroundColor = [UIColor blackColor];
|
|
|
|
|
|
|
+
|
|
|
return videoCell;
|
|
return videoCell;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -192,11 +231,13 @@
|
|
|
|
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
|
if (scrollView == self.previewContainer) {
|
|
if (scrollView == self.previewContainer) {
|
|
|
|
|
+
|
|
|
CGFloat x = scrollView.contentOffset.x / scrollView.frame.size.width;
|
|
CGFloat x = scrollView.contentOffset.x / scrollView.frame.size.width;
|
|
|
int idx = (int)x;
|
|
int idx = (int)x;
|
|
|
if (idx == x) {
|
|
if (idx == x) {
|
|
|
if (self.currentIndex != idx) {
|
|
if (self.currentIndex != idx) {
|
|
|
self.currentIndex = idx;
|
|
self.currentIndex = idx;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -219,6 +260,17 @@
|
|
|
|
|
|
|
|
#pragma mark - Private
|
|
#pragma mark - Private
|
|
|
|
|
|
|
|
|
|
+- (NSUInteger)contentOffsetForIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
+ NSUInteger idx = indexPath.row;
|
|
|
|
|
+ if (idx == 0) {
|
|
|
|
|
+ idx = self.photos.count - 1;
|
|
|
|
|
+ }else if (idx == self.photos.count + 1) {
|
|
|
|
|
+ idx = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ idx = idx - 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ return idx;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- (void) photoCell:(PhotoPreviewCell *)cell loadImage:(NSDictionary *)item_json {
|
|
- (void) photoCell:(PhotoPreviewCell *)cell loadImage:(NSDictionary *)item_json {
|
|
|
|
|
|