点击图片 实现图片放大或视频播放功能

第三方 MMHVideoPhotoGallery

-(void)showImages:(NSArray *)array atIndex:(NSInteger)index

{

if(!array || array.count == 0){

return;

}

 

if(index < 0 || index > array.count){

index = 0;

}

 

NSMutableArray *photoArray = [NSMutableArray new];

 

for(PhotoItem *photo in array){

MHGalleryItem *item;

NSString *url = photo.pUrl;

if([url hasSuffix:@”.mp4″]){

item =  [MHGalleryItem.alloc initWithURL:url galleryType:MHGalleryTypeVideo];

item.shouldPlayVideo = YES;

}else{

item =  [MHGalleryItem.alloc initWithURL:url galleryType:MHGalleryTypeImage];

}

//照片文字描述

if([StringUtil stringIsNotBlank:photo.title] || [StringUtil stringIsNotBlank:photo.note]){

NSString *description = [NSString stringWithFormat:@”%@\n%@”, photo.title, photo.note];

 

NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:description];

[string setAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:18],

NSForegroundColorAttributeName : UIColor.whiteColor,

NSBackgroundColorAttributeName : [UIColor colorWithWhite:0.3 alpha:0.8]}

range:NSMakeRange(0, string.length)];

item.attributedString = string;

}

 

[photoArray addObject:item];

}

 

MHUICustomization *customUI = [MHUICustomization new];

customUI.showOverView = NO;

customUI.hideShare = NO;

customUI.barButtonsTintColor = Color_Mian;

 

MHGalleryController *gallery = [[MHGalleryController alloc]initWithPresentationStyle:MHGalleryViewModeImageViewerNavigationBarHidden];

gallery.galleryItems = photoArray;

gallery.presentationIndex = index;

gallery.UICustomization = customUI;

__weak MHGalleryController *blockGallery = gallery;

gallery.finishedCallback = ^(NSInteger currentIndex,UIImage *image,MHTransitionDismissMHGallery *interactiveTransition,MHGalleryViewMode viewMode){

[blockGallery dismissViewControllerAnimated:YES dismissImageView:nil completion:^{

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];//白色

}];

};

 

[self presentMHGalleryController:gallery animated:YES completion:nil];

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注