如何在我自己的iphone图像库应用程序中添加MWPhotoBrowser项目参考?

如何在我自己的iphone图像库应用程序中添加MWPhotoBrowser项目参考?,iphone,xcode,macos,Iphone,Xcode,Macos,我想做一个像原生iphone照片库一样的iphone应用程序…我发现了一个项目MWPhotoBrowser,现在我想使用这个项目的一些功能…但我不知道如何做…我是iphone应用程序开发的新手 首先,您必须在项目中导入您下载的框架。然后,您必须为.h和.m文件创建一个类viewController,并按如下方式设置视图: h应该是这样的 #import <UIKit/UIKit.h> #import "MWPhotoBrowser.h" @interface PhotoLoader

我想做一个像原生iphone照片库一样的iphone应用程序…我发现了一个项目MWPhotoBrowser,现在我想使用这个项目的一些功能…但我不知道如何做…我是iphone应用程序开发的新手

首先,您必须在项目中导入您下载的框架。然后,您必须为.h和.m文件创建一个类viewController,并按如下方式设置视图: h应该是这样的

#import <UIKit/UIKit.h>
#import "MWPhotoBrowser.h"

@interface PhotoLoader : UIViewController<MWPhotoBrowserDelegate> {
    NSArray *_photos;
    UISegmentedControl *_segmentedControl;
}
@property (nonatomic, retain) NSArray *photos;
@end
//  PhotoLoader.m


#import "PhotoLoader.h"

@interface PhotoLoader ()

@end

@implementation PhotoLoader
@synthesize photos = _photos;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Create browser
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;

    //show your photo whit url

    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://Url.Photo.Here.jpg"]]];
    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://http://Url.Photo.Here.jpg"]]];
    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://http://Url.Photo.Here.jpg"]]];
    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://http://Url.Photo.Here.jpg"]]];
    // Do any additional setup after loading the view.
}
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}
- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}
- (void)segmentChange {
    [self.tableView reloadData];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

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

@end
档案。我应该是这样的

#import <UIKit/UIKit.h>
#import "MWPhotoBrowser.h"

@interface PhotoLoader : UIViewController<MWPhotoBrowserDelegate> {
    NSArray *_photos;
    UISegmentedControl *_segmentedControl;
}
@property (nonatomic, retain) NSArray *photos;
@end
//  PhotoLoader.m


#import "PhotoLoader.h"

@interface PhotoLoader ()

@end

@implementation PhotoLoader
@synthesize photos = _photos;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Create browser
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;

    //show your photo whit url

    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://Url.Photo.Here.jpg"]]];
    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://http://Url.Photo.Here.jpg"]]];
    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://http://Url.Photo.Here.jpg"]]];
    [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://http://Url.Photo.Here.jpg"]]];
    // Do any additional setup after loading the view.
}
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}
- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}
- (void)segmentChange {
    [self.tableView reloadData];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

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

@end
仅此而已。

请参阅此处 还有看。 这可能会有帮助。 还有其他一些方法也有帮助。
他们都遵循相同的缩放、滚动、缓存等步骤。

github页面对我来说非常有用。他们有很棒的教程。这是链接:

你好,马穆努尔。如果这个答案是正确的,请考虑在答案上设置复选标记。这将有助于后续读者。