1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// 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