MWPhotoBrowser 屬性詳解 和代理解釋


--------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];

}


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM