博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MWPhotoBrowser 属性详解 和代理解释
阅读量:4700 次
发布时间:2019-06-09

本文共 4110 字,大约阅读时间需要 13 分钟。

--------0.MWPhoto简单属性解释----------------

 

MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3629/3339128908_7aecabc34b.jpg"]]; photo.caption = @"在将photo添加到数组中时,可以在这里设置标题名字";

 

 

   photo = [MWPhotophotoWithURL:[NSURLfileURLWithPath:[[NSBundlemainBundle]pathForResource:@"photo2"ofType:@"jpg"]]];

            photo.caption =@"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";

[photos addObject:photo];

效果图

==============================1.属性详解==========================

 

MWPhotoBrowser *browser = [[MWPhotoBrowseralloc]initWithDelegate:self];

  //分享按钮,默认是

  browser.displayActionButton =NO;

  //底部是否分页切换导航,默认否

  browser.displayNavArrows =NO;

  是否显示选择按钮在图片上,默认否

  browser.displaySelectionButtons =YES;

  //控制条件控件是否显示,默认否

  browser.alwaysShowControls =NO;

 

  //自动适用大小,默认是

  browser.zoomPhotosToFill =YES;

  //是否允许用网格查看所有图片,默认是

  browser.enableGrid =NO;

  是否第一张,默认否

  browser.startOnGrid =YES;

 

  //是否开始对缩略图网格代替第一张照片

  browser.enableSwipeToDismiss =NO;

 

  //是否自动播放视频

  browser.autoPlayOnAppear =NO;

 

  //播放页码

  [browser setCurrentPhotoIndex:0];

 

  //自定义选择按钮的样式

  //大图时显示选择按钮,(图片大小要和ImageSelectedOn图大小一致)

  // browser.customImageSelectedIconName = @"选中";

 

  //选择多图的时候,图片大小要和ImageSelectedSmallOn图大小一致)

  //  browser.customImageSelectedSmallIconName = @"选中";

 

  [self.navigationControllerpushViewController:browseranimated:YES];

 

==============================2.代理方法解释==========================

 

/*****************************必须实现的代理方法********************************/

//有多少个图片要显示

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {

  returnself.photoesArray.count;

}

 

//在具体的index中,显示网络加载或者本地的某一个图片

- (id<MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser

               photoAtIndex:(NSUInteger)index {

  if (index <self.photoesArray.count) {

    return [self.photoesArrayobjectAtIndex:index];

  }

  returnnil;

}

图片效果图:

 

/*****************************可选实现的代理方法********************************/

//自定义标题

- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser

      titleForPhotoAtIndex:(NSUInteger)index {

  return [NSStringstringWithFormat:@"%lu/%lu", (unsignedlong)index,

                                    (unsignedlong)self.photoesArray.count];

}

图片效果图:

 

 

//加载多张网络缩略图(enableGrid YES)时,才可以实现该委托方法

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index{

    if (index <self.photoesArray.count) {

        return [self.photoesArrayobjectAtIndex:index];

    }

    returnnil;

}

效果图显示 1 和 2:

 

//自定义底部视图,继承MWCaptionView这个类,在子类中重写-setupCaption -sizeThatFits:,或者加视图。

- (MWCaptionView *)photoBrowser:(MWPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index{

    MWPhoto *photo = [self.photoesArrayobjectAtIndex:index];

    MWCaptionView *captionView = [[MWCaptionViewalloc]initWithPhoto:photo];

//    captionView.

    return captionView;

 

}

效果视图:

 

//displayActionButton(分享按钮)设置为YES时,这个方法才会触发。之前的分享动作就不会出现。

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index{

    NSLog(@"content %lu",(unsignedlong)index);

}

效果图

 

 

//当前将要显示第几张

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index{

    NSLog(@"content %lu",(unsignedlong)index);

}

效果图:

 

 

//设置将要显示的视图,是否被选或者没有被选,把它放到一个数组中。

- (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index {

    return [[_selectionsobjectAtIndex:index] boolValue];

}

//当前显示图片,选择按钮是否被选,或者没有被选,会触发这个方法

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected {

    [_selectionsreplaceObjectAtIndex:index withObject:[NSNumbernumberWithBool:selected]];

    NSLog(@"Photo at index %lu selected %@", (unsignedlong)index, selected ? @"YES" :@"NO");

}

 

 

如果是modal出来的,必须手动dismiss

/*

 当要modal出来的时候,需要使用包装上一个UINavigationController,它可以来管理多张图问题。

 UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser];

 nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

 [self presentViewController:nc animated:YES completion:nil];

 

 */

- (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser{

    [self dismissViewControllerAnimated:YES completion:nil];

}

 

转载于:https://www.cnblogs.com/dreamDeveloper/p/6055944.html

你可能感兴趣的文章
团队项目(第五周)
查看>>
SQL 优化经验总结34条
查看>>
开源 视频会议 收藏
查看>>
核心J2EE模式 - 截取过滤器
查看>>
.net开源CMS
查看>>
JdbcTemplate
查看>>
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>