// // MyPreviewController.m // gengmei_flutter_plugin // // Created by Apple on 2019/11/3. // #import #include "MyPreviewController.h" @interface MyPreviewController() @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]; UIButton *backBtn =[UIButton buttonWithType:(UIButtonTypeCustom)]; backBtn.frame = CGRectMake(10, 20, 50, 50); [backBtn setTitle:@"返回" forState:UIControlStateNormal]; [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // [backBtn setImage:[UIImage imageNamed:@"fanhuijiantou"] forState:UIControlStateNormal]; // backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 20); [backBtn addTarget:self action:@selector(onLibraryButtonClicked) forControlEvents:(UIControlEventTouchUpInside)]; [self.view addSubview:backBtn]; // self.navigationItem.backBarButtonItem = backBtn; // [self configUI]; } -(void)onLibraryButtonClicked{ [self dismissViewControllerAnimated:YES completion:nil]; } - (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]; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; } } #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