MyPreviewController.m 3.56 KB
//
//  MyPreviewController.m
//  gengmei_flutter_plugin
//
//  Created by Apple on 2019/11/3.
//

#import <Foundation/Foundation.h>
#include "MyPreviewController.h"

@interface MyPreviewController()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView * scrollView;
@property (nonatomic, strong) UIView * titleView;
@property (nonatomic, strong) UILabel * titleLab;
@property (nonatomic, strong) NSMutableArray * playerArray;
@property (nonatomic, strong) UIImageView * videoOverLay;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, assign) BOOL isHidden;
@property (nonatomic, strong) id timeObserver;
@property(nonatomic,strong)UIImageView* imageView;
@end

@implementation MyPreviewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    
    self.isHidden = NO;
    _imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    _imageView.clipsToBounds  = YES;
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    _imageView.contentScaleFactor = [[UIScreen mainScreen] scale];
    _imageView.backgroundColor = [UIColor clearColor];
    _imageView.tag = 1000;
    [self.view addSubview:_imageView];
    //    [self configUI];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

#pragma mark - 手势处理
- (void)doubleTapGestureCallback:(UITapGestureRecognizer *)gesture
{
    [self resetIndex];
    UIScrollView *scrollView = [_scrollView viewWithTag:100+_index];
    CGFloat zoomScale = scrollView.zoomScale;
    if (zoomScale == scrollView.maximumZoomScale) {
        zoomScale = 0;
    } else {
        zoomScale = scrollView.maximumZoomScale;
    }
    [UIView animateWithDuration:0.35 animations:^{
        scrollView.zoomScale = zoomScale;
    }];
}



#pragma mark - 图像加载|移除


- (void)setImagePrePath:(NSString*)path{
    self->_imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:path]];
}

- (void)setImagePre:(PHAsset*)asset
{
    
    PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init];
    imageRequestOption.synchronous =NO;
    imageRequestOption.networkAccessAllowed = YES;
    imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat;
    imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
    imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;
    
    int picWidth=[asset pixelWidth];
    int picHeight=[asset pixelHeight];
    float tempScareSize=1;
    float limit=1560.0;
    float max=MAX(picWidth, picHeight);
    if(max>limit){
        tempScareSize=limit/max;
    }
    CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
    [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
        self->_imageView.image = result;
    }];
}

- (void)resetIndex
{
    CGFloat pageWidth = _scrollView.frame.size.width;
    _index = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}

#pragma mark - UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return [scrollView viewWithTag:1000];
}


#pragma mark -
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end