2015-09-28 54 views
-5

我无法永远阅读并尝试理解MWPhotoBrowser示例项目的整个代码。我无法弄清楚这个项目从哪里获取照片数据。自上周以来,我一直在试图理解这个项目。使用MWPhotoBrowser浏览所有相册

所以这里的东西,我试图做一个应用程序,使用这个MWPhotoBrowser(https://github.com/mwaterfall/MWPhotoBrowser/blob/master/README.md)开源项目/库。一款可以浏览手机中所有相册但使用MWPhotoBrowser的应用程序。

在MWPhotoBrowser的示例程序中,有一个示例代码如何浏览手机的本地照片。有很多例子,但我设法删除其中的一些,只保留最后一个选项。 - 图书馆照片和视频(案例:9,如果你要看代码)。

我迄今所做的:

  1. 实现从developer.apple.com开源项目(图库浏览器应用程序) - 成功实现,但我不太满意,因为MWPhotoBrowser较好,冷却器。

  2. 编辑MWPhotoBrowser的示例项目。

CODE:

// 
// Menu.m 
// MWPhotoBrowser 
// 
// Created by Michael Waterfall on 21/10/2010. 
// Copyright 2010 d3i. All rights reserved. 
// 

#import <Photos/Photos.h> 
#import "Menu.h" 
#import "SDImageCache.h" 
#import "MWCommon.h" 

@implementation Menu 

#pragma mark - 
#pragma mark View 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Test toolbar hiding 
    // [self setToolbarItems: @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil]]]; 
    // [[self navigationController] setToolbarHidden:NO animated:NO]; 
    NSLog(@"view did load...."); 

    self.title = @"MWPhotoBrowser"; 

    // Clear cache for testing 
    [[SDImageCache sharedImageCache] clearDisk]; 
    [[SDImageCache sharedImageCache] clearMemory]; 

    [self loadAssets]; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    // self.navigationController.navigationBar.barTintColor = [UIColor greenColor]; 
    // self.navigationController.navigationBar.translucent = NO; 
    // [self.navigationController setNavigationBarHidden:YES animated:YES]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    // [self.navigationController setNavigationBarHidden:NO animated:YES]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (BOOL)prefersStatusBarHidden { 
    return NO; 
} 

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { 
    return UIStatusBarAnimationNone; 
} 

#pragma mark - 
#pragma mark Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSInteger rows = 1; 
    @synchronized(_assets) { 
     if (_assets.count) rows++; 
    } 
    return rows; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    // Create 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 
    cell.accessoryType = _segmentedControl.selectedSegmentIndex == 0 ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone; 

    // Configure 
    switch (indexPath.row) { 
     case 0: { 
      cell.textLabel.text = @"Library photos and videos"; 
      cell.detailTextLabel.text = @"media from device library"; 
      break; 
     } 
     default: break; 
    } 
    return cell; 

} 

#pragma mark - 
#pragma mark Table view delegate 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSLog(@"Did Select..."); 

    // Browser 
    NSMutableArray *photos = [[NSMutableArray alloc] init]; 
    NSMutableArray *thumbs = [[NSMutableArray alloc] init]; 
    MWPhoto *photo, *thumb; 
    BOOL displayActionButton = YES; 
    BOOL displaySelectionButtons = NO; 
    BOOL displayNavArrows = NO; 
    BOOL enableGrid = YES; 
    BOOL startOnGrid = NO; 
    BOOL autoPlayOnAppear = NO; 
    //@synchronized(_assets) { 
    NSMutableArray *copy = [_assets copy]; 

    if (NSClassFromString(@"PHAsset")) { 
     // Photos library 
     UIScreen *screen = [UIScreen mainScreen]; 
     CGFloat scale = screen.scale; 
     // Sizing is very rough... more thought required in a real implementation 
     CGFloat imageSize = MAX(screen.bounds.size.width, screen.bounds.size.height) * 1.5; 
     CGSize imageTargetSize = CGSizeMake(imageSize * scale, imageSize * scale); 
     CGSize thumbTargetSize = CGSizeMake(imageSize/3.0 * scale, imageSize/3.0 * scale); 
     for (PHAsset *asset in copy) { 
      [photos addObject:[MWPhoto photoWithAsset:asset targetSize:imageTargetSize]]; 
      [thumbs addObject:[MWPhoto photoWithAsset:asset targetSize:thumbTargetSize]]; 
     } 
    } 

    else { 
     // Assets library 
     for (ALAsset *asset in copy) { 
      MWPhoto *photo = [MWPhoto photoWithURL:asset.defaultRepresentation.url]; 
      [photos addObject:photo]; 
      MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageWithCGImage:asset.thumbnail]]; 
      [thumbs addObject:thumb]; 
      if ([asset valueForProperty:ALAssetPropertyType] == ALAssetTypeVideo) { 
       photo.videoURL = asset.defaultRepresentation.url; 
       thumb.isVideo = true; 
      } 
     } 
    } 
    //} 

    self.photos = photos; 
    self.thumbs = thumbs; 

    // Create browser 
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; 
    browser.displayActionButton = displayActionButton; 
    browser.displayNavArrows = displayNavArrows; 
    browser.displaySelectionButtons = displaySelectionButtons; 
    browser.alwaysShowControls = displaySelectionButtons; 
    browser.zoomPhotosToFill = YES; 
    browser.enableGrid = enableGrid; 
    browser.startOnGrid = startOnGrid; 
    browser.enableSwipeToDismiss = NO; 
    browser.autoPlayOnAppear = autoPlayOnAppear; 
    [browser setCurrentPhotoIndex:0]; 

    // Test custom selection images 
    // browser.customImageSelectedIconName = @"ImageSelected.png"; 
    // browser.customImageSelectedSmallIconName = @"ImageSelectedSmall.png"; 

    // Reset selections 
    if (displaySelectionButtons) { 
     _selections = [NSMutableArray new]; 
     for (int i = 0; i < photos.count; i++) { 
      [_selections addObject:[NSNumber numberWithBool:NO]]; 
     } 
    } 

    // Show 
    [self.navigationController pushViewController:browser animated:YES]; 


} 

#pragma mark - MWPhotoBrowserDelegate 

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser { 
    return _photos.count; 
} 

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index { 
    if (index < _photos.count) 
     return [_photos objectAtIndex:index]; 
    return nil; 
} 

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index { 
    if (index < _thumbs.count) 
     return [_thumbs objectAtIndex:index]; 
    return nil; 
} 

//- (MWCaptionView *)photoBrowser:(MWPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index { 
// MWPhoto *photo = [self.photos objectAtIndex:index]; 
// MWCaptionView *captionView = [[MWCaptionView alloc] initWithPhoto:photo]; 
// return [captionView autorelease]; 
//} 

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index { 
    NSLog(@"ACTION!"); 
} 

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index { 
    NSLog(@"Did start viewing photo at index %lu", (unsigned long)index); 
} 

- (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index { 
    return [[_selections objectAtIndex:index] boolValue]; 
} 

//- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index { 
// return [NSString stringWithFormat:@"Photo %lu", (unsigned long)index+1]; 
//} 

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected { 
    [_selections replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:selected]]; 
    NSLog(@"Photo at index %lu selected %@", (unsigned long)index, selected ? @"YES" : @"NO"); 
} 




////////////// 

#pragma mark - Load Assets 

- (void)loadAssets { 
    if (NSClassFromString(@"PHAsset")) { 

     // Check library permissions 
     PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 
     if (status == PHAuthorizationStatusNotDetermined) { 
      [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 
       if (status == PHAuthorizationStatusAuthorized) { 
        [self performLoadAssets]; 
       } 
      }]; 
     } else if (status == PHAuthorizationStatusAuthorized) { 
      [self performLoadAssets]; 
     } 

    } else { 

     // Assets library 
     [self performLoadAssets]; 

    } 
} 

- (void)performLoadAssets { 

    // Initialise 
    _assets = [NSMutableArray new]; 

    // Load 
    if (NSClassFromString(@"PHAsset")) { 

     // Photos library iOS >= 8 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
      PHFetchOptions *options = [PHFetchOptions new]; 
      options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; 
      PHFetchResult *fetchResults = [PHAsset fetchAssetsWithOptions:options]; 
      [fetchResults enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
       [_assets addObject:obj]; 
      }]; 
      if (fetchResults.count > 0) { 
//    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 
      } 
     }); 

    } else { 

     // Assets Library iOS < 8 
     _ALAssetsLibrary = [[ALAssetsLibrary alloc] init]; 

     // Run in the background as it takes a while to get all assets from the library 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

      NSMutableArray *assetGroups = [[NSMutableArray alloc] init]; 
      NSMutableArray *assetURLDictionaries = [[NSMutableArray alloc] init]; 

      // Process assets 
      void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 
       if (result != nil) { 
        NSString *assetType = [result valueForProperty:ALAssetPropertyType]; 
        if ([assetType isEqualToString:ALAssetTypePhoto] || [assetType isEqualToString:ALAssetTypeVideo]) { 
         [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]]; 
         NSURL *url = result.defaultRepresentation.url; 
         [_ALAssetsLibrary assetForURL:url 
              resultBlock:^(ALAsset *asset) { 
               if (asset) { 
                @synchronized(_assets) { 
                 [_assets addObject:asset]; 
                 if (_assets.count == 1) { 
                  // Added first asset so reload data 
                  [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 
                 } 
                } 
               } 
              } 
             failureBlock:^(NSError *error){ 
              NSLog(@"operation was not successfull!"); 
             }]; 

        } 
       } 
      }; 

      // Process groups 
      void (^ assetGroupEnumerator) (ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) { 
       if (group != nil) { 
        [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:assetEnumerator]; 
        [assetGroups addObject:group]; 
       } 
      }; 

      // Process! 
      [_ALAssetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll 
              usingBlock:assetGroupEnumerator 
              failureBlock:^(NSError *error) { 
               NSLog(@"There is an error"); 
              }]; 

     }); 

    } 

} 

@end 
  • 接着,我试图使一个的ViewController示例项目的故事板的内部,断开导航控制器之间的连接表视图控制器。我将导航控制器连接到ViewController。然后,我将新创建的类名为:MainViewController.m分配给故事板中的ViewController。

  • 我复制了所有代码,或者更确切地说,将Main.m(连接到示例项目的表视图的类)的代码的所有实现复制到我的MainViewController.m。因此,这里是我的代码至今:

    // 
    

    // MainViewController.m // MWPhotoBrowser // // 通过创建格伦在15年9月28日。 //版权所有(

  • c)2015迈克尔瀑布。版权所有。 //

    #import "MainViewController.h" 
    #import <Photos/Photos.h> 
    // #import "Menu.h" 
    #import "SDImageCache.h" 
    #import "MWCommon.h" 
    
    @interface MainViewController() 
    { 
        MWPhotoBrowser *browser; 
    } 
    @end 
    
    @implementation MainViewController 
    
    - (void)viewDidLoad { 
        [super viewDidLoad]; 
        // Do any additional setup after loading the view. 
        [self mwSetup]; 
    
        self.title = @"MWPhotoBrowser"; 
    
        // Clear cache for testing 
        [[SDImageCache sharedImageCache] clearDisk]; 
        [[SDImageCache sharedImageCache] clearMemory]; 
    
        [self loadAssets]; 
    
        } 
    
    - (void)didReceiveMemoryWarning { 
        [super didReceiveMemoryWarning]; 
        // Dispose of any resources that can be recreated. 
    } 
    
    
    - (void)viewWillAppear:(BOOL)animated { 
        [super viewWillAppear:animated]; 
        // self.navigationController.navigationBar.barTintColor = [UIColor greenColor]; 
        // self.navigationController.navigationBar.translucent = NO; 
        // [self.navigationController setNavigationBarHidden:YES animated:YES]; 
    } 
    
    - (void)viewWillDisappear:(BOOL)animated { 
        [super viewWillDisappear:animated]; 
        // [self.navigationController setNavigationBarHidden:NO animated:YES]; 
    } 
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
        return YES; 
    } 
    
    - (BOOL)prefersStatusBarHidden { 
        return NO; 
    } 
    
    - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { 
        return UIStatusBarAnimationNone; 
    } 
    
    
    - (void)mwSetup 
    { 
    
    
        NSLog(@"Did Select..."); 
    
        // Browser 
        NSMutableArray *photos = [[NSMutableArray alloc] init]; 
        NSMutableArray *thumbs = [[NSMutableArray alloc] init]; 
        MWPhoto *photo, *thumb; 
        BOOL displayActionButton = YES; 
        BOOL displaySelectionButtons = NO; 
        BOOL displayNavArrows = NO; 
        BOOL enableGrid = YES; 
        BOOL startOnGrid = NO; 
        BOOL autoPlayOnAppear = NO; 
        //@synchronized(_assets) { 
        NSMutableArray *copy = [_assets copy]; 
    
        if (NSClassFromString(@"PHAsset")) { 
         // Photos library 
         UIScreen *screen = [UIScreen mainScreen]; 
         CGFloat scale = screen.scale; 
         // Sizing is very rough... more thought required in a real implementation 
         CGFloat imageSize = MAX(screen.bounds.size.width, screen.bounds.size.height) * 1.5; 
         CGSize imageTargetSize = CGSizeMake(imageSize * scale, imageSize * scale); 
         CGSize thumbTargetSize = CGSizeMake(imageSize/3.0 * scale, imageSize/3.0 * scale); 
         for (PHAsset *asset in copy) { 
          [photos addObject:[MWPhoto photoWithAsset:asset targetSize:imageTargetSize]]; 
          [thumbs addObject:[MWPhoto photoWithAsset:asset targetSize:thumbTargetSize]]; 
         } 
        } 
    
        else { 
         // Assets library 
         for (ALAsset *asset in copy) { 
          MWPhoto *photo = [MWPhoto photoWithURL:asset.defaultRepresentation.url]; 
          [photos addObject:photo]; 
          MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageWithCGImage:asset.thumbnail]]; 
          [thumbs addObject:thumb]; 
          if ([asset valueForProperty:ALAssetPropertyType] == ALAssetTypeVideo) { 
           photo.videoURL = asset.defaultRepresentation.url; 
           thumb.isVideo = true; 
          } 
         } 
        } 
        //} 
    
        self.photos = photos; 
        self.thumbs = thumbs; 
    
        // Create browser 
        browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; 
        browser.displayActionButton = displayActionButton; 
        browser.displayNavArrows = displayNavArrows; 
        browser.displaySelectionButtons = displaySelectionButtons; 
        browser.alwaysShowControls = displaySelectionButtons; 
        browser.zoomPhotosToFill = YES; 
        browser.enableGrid = enableGrid; 
        browser.startOnGrid = startOnGrid; 
        browser.enableSwipeToDismiss = NO; 
        browser.autoPlayOnAppear = autoPlayOnAppear; 
        [browser setCurrentPhotoIndex:0]; 
    
        // Test custom selection images 
        // browser.customImageSelectedIconName = @"ImageSelected.png"; 
        // browser.customImageSelectedSmallIconName = @"ImageSelectedSmall.png"; 
    
        // Reset selections 
        if (displaySelectionButtons) { 
         _selections = [NSMutableArray new]; 
         for (int i = 0; i < photos.count; i++) { 
          [_selections addObject:[NSNumber numberWithBool:NO]]; 
         } 
        } 
    
        // Show 
    [self.navigationController pushViewController:browser animated:YES]; 
        //[self.view addSubview:browser.view]; 
    
    } 
    
    
    
    
    
    #pragma mark - MWPhotoBrowserDelegate 
    
    - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser { 
        return _photos.count; 
    } 
    
    - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index { 
        if (index < _photos.count) 
         return [_photos objectAtIndex:index]; 
        return nil; 
    } 
    
    - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index { 
        if (index < _thumbs.count) 
         return [_thumbs objectAtIndex:index]; 
        return nil; 
    } 
    
    //- (MWCaptionView *)photoBrowser:(MWPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index { 
    // MWPhoto *photo = [self.photos objectAtIndex:index]; 
    // MWCaptionView *captionView = [[MWCaptionView alloc] initWithPhoto:photo]; 
    // return [captionView autorelease]; 
    //} 
    
    - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index { 
        NSLog(@"ACTION!"); 
    } 
    
    - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index { 
        NSLog(@"Did start viewing photo at index %lu", (unsigned long)index); 
    } 
    
    - (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index { 
        return [[_selections objectAtIndex:index] boolValue]; 
    } 
    
    //- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index { 
    // return [NSString stringWithFormat:@"Photo %lu", (unsigned long)index+1]; 
    //} 
    
    - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected { 
        [_selections replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:selected]]; 
        NSLog(@"Photo at index %lu selected %@", (unsigned long)index, selected ? @"YES" : @"NO"); 
    } 
    
    
    
    
    #pragma mark - Load Assets 
    
    - (void)loadAssets { 
        if (NSClassFromString(@"PHAsset")) { 
    
         // Check library permissions 
         PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 
         if (status == PHAuthorizationStatusNotDetermined) { 
          [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 
           if (status == PHAuthorizationStatusAuthorized) { 
            [self performLoadAssets]; 
           } 
          }]; 
         } else if (status == PHAuthorizationStatusAuthorized) { 
          [self performLoadAssets]; 
         } 
    
        } else { 
    
         // Assets library 
         [self performLoadAssets]; 
    
        } 
    } 
    
    - (void)performLoadAssets { 
    
        // Initialise 
        _assets = [NSMutableArray new]; 
    
        // Load 
        if (NSClassFromString(@"PHAsset")) { 
    
         // Photos library iOS >= 8 
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
          PHFetchOptions *options = [PHFetchOptions new]; 
          options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; 
          PHFetchResult *fetchResults = [PHAsset fetchAssetsWithOptions:options]; 
          [fetchResults enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
           [_assets addObject:obj]; 
          }]; 
          if (fetchResults.count > 0) { 
           [browser reloadData]; } 
         }); 
    
        } else { 
    
         // Assets Library iOS < 8 
         _ALAssetsLibrary = [[ALAssetsLibrary alloc] init]; 
    
         // Run in the background as it takes a while to get all assets from the library 
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    
          NSMutableArray *assetGroups = [[NSMutableArray alloc] init]; 
          NSMutableArray *assetURLDictionaries = [[NSMutableArray alloc] init]; 
    
          // Process assets 
          void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 
           if (result != nil) { 
            NSString *assetType = [result valueForProperty:ALAssetPropertyType]; 
            if ([assetType isEqualToString:ALAssetTypePhoto] || [assetType isEqualToString:ALAssetTypeVideo]) { 
             [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]]; 
             NSURL *url = result.defaultRepresentation.url; 
             [_ALAssetsLibrary assetForURL:url 
                  resultBlock:^(ALAsset *asset) { 
                   if (asset) { 
                    @synchronized(_assets) { 
                     [_assets addObject:asset]; 
                     if (_assets.count == 1) { 
                      // Added first asset so reload data 
                      [browser reloadData]; 
                     } 
                    } 
                   } 
                  } 
                 failureBlock:^(NSError *error){ 
                  NSLog(@"operation was not successfull!"); 
                 }]; 
    
            } 
           } 
          }; 
    
          // Process groups 
          void (^ assetGroupEnumerator) (ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) { 
           if (group != nil) { 
            [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:assetEnumerator]; 
            [assetGroups addObject:group]; 
           } 
          }; 
    
          // Process! 
          [_ALAssetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll 
                  usingBlock:assetGroupEnumerator 
                  failureBlock:^(NSError *error) { 
                   NSLog(@"There is an error"); 
                  }]; 
    
         }); 
    
        } 
    
    } 
    
    @end 
    

    请帮忙。有人可以帮我编辑第二代码的格式吗?谢谢。

    +0

    为什么要降薪?... – user5295097

    回答

    -2

    好的,所以我得到了它的工作。基本上,MWPhotoBrowser在加载之前需要第一个视图控制器。

    例如,在示例项目中,第一个屏幕是Table View。然后,您将在9行之间进行选择,之后将显示MWPhotoBrowser视图控制器。

    在我的实现中,我只是做了第一个视图控制器,然后添加了一个按钮。当你点击按钮时,MWPhotoBrowser将被显示。

    这就是MWPhotoBrowser的工作原理。如果您在ViewWillAppear,ViewDidLoad,ViewDidAppear中推送MWPhotoBrowser,它不会加载照片和视频。

    现在,我必须学习或知道如何加载来自不同专辑的视频和照片。

    相关问题