Просмотр исходного кода

1.修复Homer Model Photo List卡顿,抽取PhotoList到Common。

Pen Li 8 лет назад
Родитель
Сommit
db1ef92711

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 17 - 0
RedAnt ERP Mobile/common/PhotoList/Controller/ContentPreviewController.h

@@ -0,0 +1,17 @@
+//
+//  NewPhotoPreviewController.h
+//  RA Image
+//
+//  Created by Jack on 2017/6/14.
+//  Copyright © 2017年 USAI. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface ContentPreviewController : UIViewController
+
+@property (nonatomic,strong) NSDictionary *content;
+
+- (void)setOffset:(NSUInteger)offset;
+
+@end

+ 414 - 0
RedAnt ERP Mobile/common/PhotoList/Controller/ContentPreviewController.m

@@ -0,0 +1,414 @@
+//
+//  NewPhotoPreviewController.m
+//  RA Image
+//
+//  Created by Jack on 2017/6/14.
+//  Copyright © 2017年 USAI. All rights reserved.
+//
+
+#import "ContentPreviewController.h"
+#import "PhotoPreviewCell.h"
+#import "VideoPreviewCell.h"
+
+#import "iSalesDB.h"
+#import "AppDelegate.h"
+
+
+@interface ContentPreviewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
+
+@property (nonatomic,assign) NSUInteger currentIndex;
+@property (strong, nonatomic) IBOutlet UILabel *indicator;
+@property (strong, nonatomic) IBOutlet UICollectionView *previewContainer;
+
+@property (nonatomic,strong) NSArray *photos;
+
+@property (nonatomic,strong) UIView *mask;
+
+@property (nonatomic,assign) BOOL hideNavigationBar;
+
+@end
+
+@implementation ContentPreviewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+//    self.automaticallyAdjustsScrollViewInsets = NO;
+//    self.navigationController.navigationBar.translucent = NO;
+//    self.edgesForExtendedLayout = UIRectEdgeNone;
+
+    UIView *v = [UIView new];
+    [self.view insertSubview:v atIndex:0];
+    
+    NSMutableArray *tmpArr = [NSMutableArray array];
+    int count = [[self.content objectForKey:@"count"] intValue];
+    for (int i = 0; i < count; i++) {
+        NSDictionary *item = [self.content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
+        [tmpArr addObject:item];
+    }
+    self.photos = [tmpArr copy];
+    
+    self.indicator.layer.cornerRadius = 20;
+    self.indicator.layer.masksToBounds = YES;
+    
+    self.previewContainer.pagingEnabled = YES;
+    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
+    self.indicator.text = offset;
+   
+    
+    
+    self.hideNavigationBar = self.navigationController.isNavigationBarHidden;
+    
+    self.navigationController.navigationBarHidden = YES;
+    
+    // 掩藏滚动
+    [self.view insertSubview:self.mask belowSubview:self.indicator];
+}
+
+- (void)viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
+}
+
+- (void)viewDidLayoutSubviews {
+    [super viewDidLayoutSubviews];
+
+    
+//    if (self.currentIndex > 0) {
+//        [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
+//    }
+    
+//    [self scrollToIndex:self.currentIndex + 1];
+   [self.previewContainer setContentOffset:CGPointMake((self.currentIndex + 1) * CGRectGetWidth(self.previewContainer.frame), 0) animated:YES];
+
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+    [super viewDidAppear:animated];
+    
+//    [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
+    
+    __weak typeof(self) weakself = self;
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        sleep(0.25);
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [weakself.mask removeFromSuperview];
+            weakself.mask = nil;
+        });
+
+    });
+}
+
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
+    
+    // 重新布局 Item 大小
+    [self.previewContainer.collectionViewLayout invalidateLayout];
+
+    // 重新布局Item位置
+//    [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:32 animated:NO];
+    [self scrollToIndex:self.currentIndex + 1];
+}
+
+- (BOOL)prefersStatusBarHidden {
+    return YES;
+}
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // 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
+
+- (void)setOffset:(NSUInteger)offset {
+    [self setCurrentIndex:offset];
+}
+
+//- (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
+
+- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
+    return collectionView.bounds.size;
+}
+
+- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
+    return 0;
+}
+
+- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
+    return 0;
+}
+
+- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
+    return UIEdgeInsetsZero;
+}
+
+#pragma mark - CollectionView Delegate
+
+- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
+
+    
+    
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    NSDictionary *item = [self.photos objectAtIndex:idx];
+    NSString *type = [item objectForKey:@"type"];
+    
+    if ([type isEqualToString:@"image"]) {
+        PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
+        
+        [self photoCell:preCell loadImage:item];
+        
+
+        
+    } else if ([type isEqualToString:@"video"]) {
+        
+        VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
+        videoCell.item = item;
+
+        
+    }
+}
+
+- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
+    
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    NSDictionary *item = [self.photos objectAtIndex:idx];
+    NSString *type = [item objectForKey:@"type"];
+    
+    if ([type isEqualToString:@"image"]) {
+        PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
+        UIScrollView *sc = preCell.scrollView;
+        sc.zoomScale = 1;
+        sc.contentSize = CGSizeZero;
+        sc.contentOffset = CGPointZero;
+    } else if ([type isEqualToString:@"video"]) {
+        
+        VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
+
+        [videoCell reset];
+    }
+}
+
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
+    
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    NSDictionary *item = [self.photos objectAtIndex:idx];
+    NSString *type = [item objectForKey:@"type"];
+    
+    if ([type isEqualToString:@"video"]) {
+        
+        VideoPreviewCell *videoCell = (VideoPreviewCell *)[collectionView cellForItemAtIndexPath:indexPath];
+        
+        [videoCell play];
+    }
+}
+
+
+#pragma mark - CollectionView DataSource
+
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
+    return self.photos.count + 2;
+}
+
+- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
+    
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    
+    NSDictionary *item = [self.photos objectAtIndex:idx];
+    NSString *type = [item objectForKey:@"type"];
+    
+    if ([type isEqualToString:@"image"]) {
+        
+        PhotoPreviewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoPreviewCell" forIndexPath:indexPath];
+        cell.scrollView.delegate = self;
+        return cell;
+        
+    } else if ([type isEqualToString:@"video"]) {
+        
+        VideoPreviewCell *videoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoPreviewCell" forIndexPath:indexPath];
+
+        return videoCell;
+    }
+    
+    return nil;
+}
+
+#pragma mark - ScrollView Delegate
+
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
+//    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;
+//                
+//            }
+//        }
+//    }
+}
+
+- (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];
+    } else {
+//        idxi = ceil(idxf);
+//        if (idxi != 0 || idxi != self.photos.count + 1) {
+//            [self scrollToIndex:idxi];
+//        }
+    }
+    
+    if (idxi == 0) {
+        [self scrollToIndex:self.photos.count];
+    }
+    
+    if (idxi == self.photos.count + 1) {
+        [self scrollToIndex:1];
+    }
+    
+}
+
+- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
+    if (scrollView != self.previewContainer) {
+        return scrollView.subviews.firstObject;
+    }
+    return nil;
+}
+
+- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
+    
+    if (self.previewContainer != scrollView) {
+        
+
+    }
+}
+
+#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) {
+        idx = self.photos.count - 1;
+    }else if (idx == self.photos.count + 1) {
+        idx = 0;
+    } else {
+        idx = idx - 1;
+    }
+    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;
+    
+    NSString* img_url = [item_json valueForKey:@"s"];
+    NSString* type = item_json[@"type"];
+    
+    NSString* file_name=[img_url lastPathComponent];
+    NSData* img_data=nil;
+    
+    //  加载Image
+    if([type isEqualToString:@"video"])
+    {
+        img_data = UIImagePNGRepresentation([UIImage imageNamed:@"play"]);
+    }
+    else
+    {
+        if([item_json[@"is_localfile"] boolValue])
+            img_data = [NSData dataWithContentsOfFile:img_url];
+        else
+            img_data = [iSalesDB load_cached_img:file_name loadFrom:img_url];
+    }
+    
+    // 设置Image
+    if(img_data!=nil)
+    {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            UIImage * img =[UIImage imageWithData:img_data];
+            
+            [cell setPhoto:img];
+            
+        });
+    }
+    else
+    {
+        NSData*  downloadimg_data = nil;
+        if (!appDelegate.offline_mode) {
+            downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
+        }
+        dispatch_async(dispatch_get_main_queue(), ^{
+            
+            
+            
+            if(downloadimg_data!=nil)
+            {
+                
+                [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
+                
+                UIImage * img =[UIImage imageWithData:downloadimg_data];
+                [cell setPhoto:img];
+
+                
+            }
+            else
+            {
+                
+                
+                UIImage * img =[UIImage imageNamed:@"notfound_l"];
+                [cell setPhoto:img];
+
+                
+            }
+            
+        });
+    }
+    
+}
+
+- (IBAction)closeBtnClick:(UIButton *)sender {
+    
+    self.navigationController.navigationBarHidden = self.hideNavigationBar;
+    [self.navigationController popViewControllerAnimated:YES];
+    
+}
+
+
+@end

+ 171 - 0
RedAnt ERP Mobile/common/PhotoList/Storyboard/PhotoList.storyboard

@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+    <device id="retina5_5" orientation="portrait">
+        <adaptation id="fullscreen"/>
+    </device>
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <scenes>
+        <!--Content Preview Controller-->
+        <scene sceneID="U3N-xr-7Rz">
+            <objects>
+                <viewController storyboardIdentifier="ContentPreviewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="qZK-Vy-gaw" customClass="ContentPreviewController" sceneMemberID="viewController">
+                    <layoutGuides>
+                        <viewControllerLayoutGuide type="top" id="mc4-Qg-2g3"/>
+                        <viewControllerLayoutGuide type="bottom" id="0pB-uU-kJr"/>
+                    </layoutGuides>
+                    <view key="view" contentMode="scaleToFill" id="qtX-co-R7G">
+                        <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <subviews>
+                            <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="eUk-3I-LIa">
+                                <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
+                                <collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="10" minimumInteritemSpacing="10" id="AhJ-66-sid">
+                                    <size key="itemSize" width="414" height="735"/>
+                                    <size key="headerReferenceSize" width="0.0" height="0.0"/>
+                                    <size key="footerReferenceSize" width="0.0" height="0.0"/>
+                                    <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
+                                </collectionViewFlowLayout>
+                                <cells>
+                                    <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="PhotoPreviewCell" id="eAR-El-bRn" customClass="PhotoPreviewCell">
+                                        <rect key="frame" x="0.0" y="0.66666666666666663" width="414" height="735"/>
+                                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                                        <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+                                            <rect key="frame" x="0.0" y="0.0" width="414" height="735"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" minimumZoomScale="0.5" maximumZoomScale="3" translatesAutoresizingMaskIntoConstraints="NO" id="5Dl-d3-MLq">
+                                                    <rect key="frame" x="0.0" y="0.0" width="414" height="735"/>
+                                                    <subviews>
+                                                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="sni-z4-WnW">
+                                                            <rect key="frame" x="0.0" y="0.0" width="414" height="734.66666666666663"/>
+                                                            <subviews>
+                                                                <imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="0p1-c6-dGo">
+                                                                    <rect key="frame" x="0.0" y="0.0" width="414" height="734.66666666666663"/>
+                                                                </imageView>
+                                                            </subviews>
+                                                            <constraints>
+                                                                <constraint firstItem="0p1-c6-dGo" firstAttribute="centerY" secondItem="sni-z4-WnW" secondAttribute="centerY" id="8UX-6e-CRi"/>
+                                                                <constraint firstItem="0p1-c6-dGo" firstAttribute="centerX" secondItem="sni-z4-WnW" secondAttribute="centerX" id="Cw9-JE-ar8"/>
+                                                                <constraint firstItem="0p1-c6-dGo" firstAttribute="width" secondItem="sni-z4-WnW" secondAttribute="width" id="d0G-UK-DXO"/>
+                                                                <constraint firstItem="0p1-c6-dGo" firstAttribute="height" secondItem="sni-z4-WnW" secondAttribute="height" id="pjY-2k-kdy"/>
+                                                            </constraints>
+                                                        </view>
+                                                    </subviews>
+                                                    <constraints>
+                                                        <constraint firstItem="sni-z4-WnW" firstAttribute="top" secondItem="5Dl-d3-MLq" secondAttribute="top" id="3mP-Sy-8ZJ"/>
+                                                        <constraint firstItem="sni-z4-WnW" firstAttribute="centerX" secondItem="5Dl-d3-MLq" secondAttribute="centerX" id="4c9-Zy-NsD"/>
+                                                        <constraint firstItem="sni-z4-WnW" firstAttribute="centerY" secondItem="5Dl-d3-MLq" secondAttribute="centerY" id="GGY-7p-nOf"/>
+                                                        <constraint firstAttribute="trailing" secondItem="sni-z4-WnW" secondAttribute="trailing" id="PVO-l2-aPm"/>
+                                                        <constraint firstAttribute="bottom" secondItem="sni-z4-WnW" secondAttribute="bottom" id="WIV-ve-oT1"/>
+                                                        <constraint firstItem="sni-z4-WnW" firstAttribute="leading" secondItem="5Dl-d3-MLq" secondAttribute="leading" id="rd8-QD-VTS"/>
+                                                    </constraints>
+                                                </scrollView>
+                                            </subviews>
+                                        </view>
+                                        <constraints>
+                                            <constraint firstItem="5Dl-d3-MLq" firstAttribute="width" secondItem="eAR-El-bRn" secondAttribute="width" id="OwB-eR-E1R"/>
+                                            <constraint firstItem="5Dl-d3-MLq" firstAttribute="centerY" secondItem="eAR-El-bRn" secondAttribute="centerY" id="hQv-Uz-CBO"/>
+                                            <constraint firstItem="5Dl-d3-MLq" firstAttribute="centerX" secondItem="eAR-El-bRn" secondAttribute="centerX" id="nsu-Oh-hQQ"/>
+                                            <constraint firstItem="5Dl-d3-MLq" firstAttribute="height" secondItem="eAR-El-bRn" secondAttribute="height" id="wst-oN-7pA"/>
+                                        </constraints>
+                                        <size key="customSize" width="414" height="735"/>
+                                        <connections>
+                                            <outlet property="photoView" destination="0p1-c6-dGo" id="FII-Mz-9Qt"/>
+                                            <outlet property="scrollContentView" destination="sni-z4-WnW" id="hob-7H-hG5"/>
+                                            <outlet property="scrollView" destination="5Dl-d3-MLq" id="2Gj-Oc-6rO"/>
+                                        </connections>
+                                    </collectionViewCell>
+                                    <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="VideoPreviewCell" id="fb9-eB-NDG" customClass="VideoPreviewCell">
+                                        <rect key="frame" x="424" y="0.66666666666666663" width="414" height="735"/>
+                                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                                        <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+                                            <rect key="frame" x="0.0" y="0.0" width="414" height="735"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="g1h-px-8Fa" customClass="YTPlayerView">
+                                                    <rect key="frame" x="0.0" y="-0.33333333333331439" width="414" height="735.33333333333326"/>
+                                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
+                                                </view>
+                                                <imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="play" translatesAutoresizingMaskIntoConstraints="NO" id="Pgl-ZY-yIF">
+                                                    <rect key="frame" x="0.0" y="-0.33333333333331439" width="414" height="735.33333333333326"/>
+                                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
+                                                </imageView>
+                                            </subviews>
+                                        </view>
+                                        <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
+                                        <constraints>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="centerX" secondItem="fb9-eB-NDG" secondAttribute="centerX" id="1QL-c6-3dR"/>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="width" secondItem="fb9-eB-NDG" secondAttribute="width" id="492-Xq-8Dy"/>
+                                            <constraint firstItem="g1h-px-8Fa" firstAttribute="centerY" secondItem="fb9-eB-NDG" secondAttribute="centerY" id="EEY-c6-vl9"/>
+                                            <constraint firstItem="g1h-px-8Fa" firstAttribute="height" secondItem="fb9-eB-NDG" secondAttribute="height" id="SKL-jo-Lzt"/>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="centerY" secondItem="fb9-eB-NDG" secondAttribute="centerY" id="YwR-9C-HfW"/>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="height" secondItem="fb9-eB-NDG" secondAttribute="height" id="eeM-vX-WIb"/>
+                                            <constraint firstItem="g1h-px-8Fa" firstAttribute="centerX" secondItem="fb9-eB-NDG" secondAttribute="centerX" id="h5h-8v-rGk"/>
+                                            <constraint firstItem="g1h-px-8Fa" firstAttribute="width" secondItem="fb9-eB-NDG" secondAttribute="width" id="k9d-ie-GeL"/>
+                                        </constraints>
+                                        <size key="customSize" width="414" height="735"/>
+                                        <connections>
+                                            <outlet property="VideoImageView" destination="Pgl-ZY-yIF" id="tkf-t3-BNf"/>
+                                            <outlet property="playerView" destination="g1h-px-8Fa" id="Ydw-01-j1F"/>
+                                        </connections>
+                                    </collectionViewCell>
+                                </cells>
+                                <connections>
+                                    <outlet property="dataSource" destination="qZK-Vy-gaw" id="2qY-wX-LI0"/>
+                                    <outlet property="delegate" destination="qZK-Vy-gaw" id="Fnz-nQ-4PE"/>
+                                </connections>
+                            </collectionView>
+                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1 / 8" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="x3F-Hb-jne">
+                                <rect key="frame" x="167" y="30" width="80" height="40"/>
+                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="80" id="4nS-MH-dz0"/>
+                                    <constraint firstAttribute="height" constant="40" id="jTZ-mK-h0Z"/>
+                                </constraints>
+                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+                                <nil key="highlightedColor"/>
+                            </label>
+                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0RT-6b-F9T">
+                                <rect key="frame" x="374" y="20" width="30" height="30"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="30" id="EfS-6B-vnU"/>
+                                    <constraint firstAttribute="width" constant="30" id="Usq-qx-7G1"/>
+                                </constraints>
+                                <state key="normal" image="iv_close"/>
+                                <connections>
+                                    <action selector="closeBtnClick:" destination="qZK-Vy-gaw" eventType="touchUpInside" id="JTL-8z-Gma"/>
+                                </connections>
+                            </button>
+                        </subviews>
+                        <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
+                        <constraints>
+                            <constraint firstAttribute="trailing" secondItem="0RT-6b-F9T" secondAttribute="trailing" constant="10" id="1bv-tN-nCS"/>
+                            <constraint firstItem="0RT-6b-F9T" firstAttribute="top" secondItem="mc4-Qg-2g3" secondAttribute="bottom" id="7h0-ww-k6I"/>
+                            <constraint firstItem="eUk-3I-LIa" firstAttribute="centerX" secondItem="qtX-co-R7G" secondAttribute="centerX" id="Occ-gY-Cbn"/>
+                            <constraint firstItem="x3F-Hb-jne" firstAttribute="top" secondItem="mc4-Qg-2g3" secondAttribute="bottom" constant="10" id="PCn-1c-2Pu"/>
+                            <constraint firstItem="x3F-Hb-jne" firstAttribute="centerX" secondItem="qtX-co-R7G" secondAttribute="centerX" id="Vpc-xd-gDa"/>
+                            <constraint firstItem="eUk-3I-LIa" firstAttribute="height" secondItem="qtX-co-R7G" secondAttribute="height" id="dad-0B-yAf"/>
+                            <constraint firstItem="eUk-3I-LIa" firstAttribute="width" secondItem="qtX-co-R7G" secondAttribute="width" id="nY6-mM-Sjc"/>
+                            <constraint firstItem="eUk-3I-LIa" firstAttribute="centerY" secondItem="qtX-co-R7G" secondAttribute="centerY" id="ygr-Ka-rvN"/>
+                        </constraints>
+                    </view>
+                    <connections>
+                        <outlet property="indicator" destination="x3F-Hb-jne" id="JGA-vq-BPK"/>
+                        <outlet property="previewContainer" destination="eUk-3I-LIa" id="TYz-ym-JNG"/>
+                    </connections>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="sWf-Id-XaR" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="1871.0144927536232" y="50.54347826086957"/>
+        </scene>
+    </scenes>
+    <resources>
+        <image name="iv_close" width="32" height="32"/>
+        <image name="play" width="350" height="350"/>
+    </resources>
+</document>

+ 19 - 0
RedAnt ERP Mobile/common/PhotoList/View/PhotoPreviewCell.h

@@ -0,0 +1,19 @@
+//
+//  PhotoPreviewCell.h
+//  RA Image
+//
+//  Created by Jack on 2017/6/14.
+//  Copyright © 2017年 USAI. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface PhotoPreviewCell : UICollectionViewCell
+
+@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
+@property (strong, nonatomic) IBOutlet UIView *scrollContentView;
+@property (nonatomic,strong) IBOutlet UIImageView *photoView;
+
+- (void)setPhoto:(UIImage *)image;
+
+@end

+ 39 - 0
RedAnt ERP Mobile/common/PhotoList/View/PhotoPreviewCell.m

@@ -0,0 +1,39 @@
+//
+//  PhotoPreviewCell.m
+//  RA Image
+//
+//  Created by Jack on 2017/6/14.
+//  Copyright © 2017年 USAI. All rights reserved.
+//
+
+#import "PhotoPreviewCell.h"
+
+@implementation PhotoPreviewCell
+
+- (void)setPhoto:(UIImage *)image {
+    if (self.photoView) {
+        
+//        CGFloat width = self.bounds.size.width;
+//        CGFloat height = self.bounds.size.height;
+//        
+//        CGFloat w = image.size.width;
+//        CGFloat h = image.size.height;
+//        // 根据图片大小和ScrollView大小等比缩放,使ScrollView容得下图片
+//        float factor = width / w;
+//        w = w * factor;
+//        h = h * factor;
+//        CGRect frame = CGRectMake(0, (height - h) * 0.5, w, h);
+//
+//        self.photoView.frame = frame;
+        
+        self.photoView.image = image;
+    }
+}
+
+- (void)layoutSubviews {
+    [super layoutSubviews];
+    
+}
+
+
+@end

+ 22 - 0
RedAnt ERP Mobile/common/PhotoList/View/VideoPreviewCell.h

@@ -0,0 +1,22 @@
+//
+//  VideoPreviewCell.h
+//  iSales-NPD
+//
+//  Created by Jack on 2017/6/21.
+//  Copyright © 2017年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "YTPlayerView.h"
+
+@interface VideoPreviewCell : UICollectionViewCell
+
+@property (nonatomic,strong) NSDictionary *item;
+
+@property (strong, nonatomic) IBOutlet YTPlayerView *playerView;
+@property (strong, nonatomic) IBOutlet UIImageView *VideoImageView;
+
+- (void)reset;
+- (void)play;
+
+@end

+ 62 - 0
RedAnt ERP Mobile/common/PhotoList/View/VideoPreviewCell.m

@@ -0,0 +1,62 @@
+//
+//  VideoPreviewCell.m
+//  iSales-NPD
+//
+//  Created by Jack on 2017/6/21.
+//  Copyright © 2017年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "VideoPreviewCell.h"
+
+@interface VideoPreviewCell ()
+
+@property (nonatomic,assign) BOOL isPlay;
+
+@end
+
+@implementation VideoPreviewCell
+
+- (void)setItem:(NSDictionary *)item {
+    _item = item;
+
+}
+
+- (void)reset {
+
+    [self.playerView stopVideo];
+    self.item = nil;
+    self.isPlay = NO;
+    [self.contentView bringSubviewToFront:self.VideoImageView];
+    
+}
+
+- (void)play {
+    if (!self.isPlay) {
+        if (self.item) {
+            
+            [self.contentView bringSubviewToFront:self.playerView];
+            NSDictionary *item = self.item;
+            NSString* video_code=item[@"code"];
+            
+            NSString* video_id=[self.playerView Embed2VID:video_code];
+            
+            NSDictionary *playerVars = @{
+                                         @"playsinline" : @1,
+                                         @"autoplay" : @(1),
+                                         @"rel":@0,
+                                         @"showinfo": @0,
+                                         @"modestbranding":@0,
+                                         @"enablejsapi":@1
+                                         };
+            
+            [self.playerView loadWithVideoId:video_id playerVars:playerVars];
+            
+            self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
+            
+            self.isPlay = YES;
+        }
+
+    }
+}
+
+@end

+ 2 - 1
RedAnt ERP Mobile/iSales-GATIT.xcodeproj/project.pbxproj

@@ -1034,7 +1034,8 @@
 				42D3A49C1EFA6D36007A54C1 /* Storyboard */,
 				42D3A49E1EFA6D36007A54C1 /* View */,
 			);
-			path = PhotoList;
+			name = PhotoList;
+			path = ../common/PhotoList;
 			sourceTree = "<group>";
 		};
 		42D3A4991EFA6D36007A54C1 /* Controller */ = {

+ 2 - 1
RedAnt ERP Mobile/iSales-HOMER.xcodeproj/project.pbxproj

@@ -1042,7 +1042,8 @@
 				42D3A49C1EFA6D36007A54C1 /* Storyboard */,
 				42D3A49E1EFA6D36007A54C1 /* View */,
 			);
-			path = PhotoList;
+			name = PhotoList;
+			path = ../common/PhotoList;
 			sourceTree = "<group>";
 		};
 		42D3A4991EFA6D36007A54C1 /* Controller */ = {

+ 2 - 1
RedAnt ERP Mobile/iSales-NPD.xcodeproj/project.pbxproj

@@ -1046,7 +1046,8 @@
 				42D3A49C1EFA6D36007A54C1 /* Storyboard */,
 				42D3A49E1EFA6D36007A54C1 /* View */,
 			);
-			path = PhotoList;
+			name = PhotoList;
+			path = ../common/PhotoList;
 			sourceTree = "<group>";
 		};
 		42D3A4991EFA6D36007A54C1 /* Controller */ = {