Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

KRImageViewer is an image viewer likes Facebook Image Viewer.

branch: master

Added 2 Blocks.

latest commit 2723dc8b57
Kuo-Ming Lin authored
README.md

Screen Shot

KRImageViewer   KRImageViewer   KRImageViewer   KRImageViewer

How To Get Started

KRImageViewer which you can browsing photos from the URLs and Images ( UIImage ), that you can scroll it to change pages, pinching for zooming, and you can close the viewer with touch and drag move it or swipe it to, and it supports rotations.

#import "KRImageViewer.h"

@interface ViewController ()<KRImageViewerDelegate>

@property (nonatomic, strong) KRImageViewer *krImageViewer;

@end

@implementation ViewController

@synthesize krImageViewer;

- (void)viewDidLoad
{
    [super viewDidLoad];
    krImageViewer = [[KRImageViewer alloc] initWithDragMode:krImageViewerModeOfBoth];
    self.krImageViewer.delegate                    = self;
    self.krImageViewer.maxConcurrentOperationCount = 1;
    self.krImageViewer.dragDisapperMode            = krImageViewerDisapperAfterMiddle;
    self.krImageViewer.allowOperationCaching       = NO;
    self.krImageViewer.timeout                     = 30.0f;
    self.krImageViewer.doneButtonTitle             = @"DONE";
    //Auto supports the rotations.
    self.krImageViewer.supportsRotations           = YES;
    //It'll release caches when caches of image over than 200 photos, but it'll be holding current image to display on the viewer.
    self.krImageViewer.overCacheCountRelease       = 200;
    //Sorting Rule, Default ASC is YES, DESC is NO.
    self.krImageViewer.sortAsc                     = YES;
    [self preloads];

    [self.krImageViewer setBrowsingHandler:^(NSInteger browsingPage)
    {
        //Current Browsing Page.
        //...Do Something.
    }];

    [self.krImageViewer setScrollingHandler:^(NSInteger scrollingPage)
    {
        //Current Scrolling Page.
        //...Do Something.
    }];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.krImageViewer useKeyWindow];
    //[self.krImageViewer resetView:self.view.window];
}

/*
 * @ 允許旋轉
 */
-(BOOL)shouldAutorotate
{
    return YES;
}

/*
 * @ 允許的旋轉方向
 */
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

/*
 * @ 將要旋轉成什麼方向
 */
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    /*
     * @ If you didn't set the " self.krImageViewer.supportsRotation = YES " to auto supporting the rotations, 
     *   then you can using this method to do the rotation by yourself.
     */
    //Here to reload the KRImageViewer rotation.
    //[self.krImageViewer reloadImagesWhenRotate:toInterfaceOrientation];
}

#pragma Method Samples
-(void)preloads
{
    //To setup the Keys and URLs.
    NSDictionary *_downloads = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"http://farm9.staticflickr.com/8459/7945134514_e5a779ee5f_s.jpg", @"1",
                                @"http://farm9.staticflickr.com/8435/7944303392_a856d79802_s.jpg", @"2",
                                @"http://farm9.staticflickr.com/8449/7943919662_67f7345f8b_s.jpg", @"3",
                                nil];
    //We suggest the to preload the Images.
    [self.krImageViewer preloadImageURLs:_downloads];
}

-(void)followImageIdToFindScrollPage
{
    //To find the id '3' to setup default show up.
    [self.krImageViewer findImageScrollPageWithId:@"3"];
}

-(IBAction)browsingPreloads:(id)sender
{
    self.krImageViewer.scrollToPage = 2;
    [self.krImageViewer start];
}

-(IBAction)browsingURLs:(id)sender
{
    NSDictionary *_downloads = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"http://farm9.staticflickr.com/8459/7945134514_e5a779ee5f_s.jpg", @"1",
                                @"http://farm9.staticflickr.com/8435/7944303392_a856d79802_s.jpg", @"2",
                                @"http://farm9.staticflickr.com/8449/7943919662_67f7345f8b_s.jpg", @"3",
                                nil];

    //Another browsing method of the images.
    [self.krImageViewer browseImageURLs:_downloads];

    //Or you can browse an image as you wanna watch.
    //[self.krImageViewer browseAnImageURL:@"http://farm9.staticflickr.com/8449/7943919662_67f7345f8b_s.jpg"];
}

-(IBAction)browsingImages:(id)sender
{
    //Or you can browse UIImages.
    NSArray *_directWatchs = [NSArray arrayWithObjects:
                              [UIImage imageNamed:@"image1.png"],
                              [UIImage imageNamed:@"image2.png"],
                              [UIImage imageNamed:@"image3.png"],
                              nil];
    [self.krImageViewer browseImages:_directWatchs];
}

-(IBAction)browsingImagesPageByPage:(id)sender
{
    //When you gonna scroll the ImageViewer, it will Page by Page to download the image and show it.
    NSDictionary *_downloads = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"http://farm9.staticflickr.com/8459/7945134514_e5a779ee5f_s.jpg", @"1",
                                @"http://farm9.staticflickr.com/8435/7944303392_a856d79802_s.jpg", @"2",
                                @"http://farm9.staticflickr.com/8449/7943919662_67f7345f8b_s.jpg", @"3",
                                nil];
    //Presents pictures in follow your displaying rules.
    self.krImageViewer.forceDisplays = [NSMutableArray arrayWithObjects:@"3", @"1", @"2", nil];
    //Now, the firstShowImageId:@"2" will sort in last one and display it first. 
    [self.krImageViewer browsePageByPageImageURLs:_downloads firstShowImageId:@"2"];
}

-(IBAction)startWatchingRotationsByYourself:(id)sender
{
    [self.krImageViewer startWatchRotations];
}

-(IBAction)stopWatchingRotations:(id)sender
{
    [self.krImageViewer stopWatchRotations];
}

-(IBAction)stopWatchingRotationsAndBackToInitialOrientation:(id)sender
{
    [self.krImageViewer stopWatchRotationsAndBackToInitialRotation];
}
@end

Version

KRImageViewer now is V1.0.2.

License

KRImageViewer is available under the MIT license ( or Whatever you wanna do ). See the LICENSE file for more info.

Updated Logs

V0.9.0 added a function to fit rotations.
V0.9.1 fixed bugs.
V0.9.5 fixed bugs.
V0.9.6 fixed an issue and added a variable named " doneButtonTitle ".
V0.9.7 fixed an issue and supported auto rotations.
V1.0.0 fixed a bug and added a new variable named " overCacheCountRelease " to control the cache-memory.
V1.0.1 fixed an iOS 7 memory bug and added 2 new variables named " sortAsc " and " forceDisplays ".
V1.0.2 added 2 bloks function.

Others

KRImageViewer to offer a browser of images, It'll be liking the iOS Facebook Image Viewer in the future one day.

Something went wrong with that request. Please try again.