Skip to content

Commit

Permalink
local images demo
Browse files Browse the repository at this point in the history
  • Loading branch information
cuzv committed May 15, 2016
1 parent c3c3465 commit c930b8d
Show file tree
Hide file tree
Showing 21 changed files with 418 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -23,4 +23,4 @@ DerivedData
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#Pods/
Pods/
53 changes: 26 additions & 27 deletions Example/Application/Main.storyboard
Expand Up @@ -5,10 +5,10 @@
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Local Images Example View Controller-->
<!--Root View Controller-->
<scene sceneID="ORb-KX-OC6">
<objects>
<viewController id="j2X-ty-XLj" customClass="LocalImagesExampleViewController" sceneMemberID="viewController">
<viewController id="j2X-ty-XLj" customClass="RootViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="MNz-CB-1bu"/>
<viewControllerLayoutGuide type="bottom" id="RxE-nV-AHY"/>
Expand All @@ -23,7 +23,7 @@
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showPhotoBrowser:" destination="j2X-ty-XLj" eventType="touchUpInside" id="Xtk-sz-XGe"/>
<segue destination="f8a-f0-vAF" kind="show" id="I50-ao-2pc"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XrL-W5-Cfq">
Expand All @@ -32,37 +32,16 @@
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showPhotoBrowser:" destination="j2X-ty-XLj" eventType="touchUpInside" id="x2l-gh-ED9"/>
<segue destination="pKL-aW-u4x" kind="presentation" id="15G-v7-37I"/>
<segue destination="pKL-aW-u4x" kind="show" id="hwJ-cS-cSH"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dlT-JK-rdh">
<rect key="frame" x="0.0" y="64" width="320" height="80"/>
<color key="backgroundColor" red="1" green="0.53911389799999998" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="kuQ-cV-fme"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ZqB-cG-tej">
<rect key="frame" x="0.0" y="151" width="320" height="80"/>
<color key="backgroundColor" red="0.0" green="1" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="OzH-hS-kVr"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="XrL-W5-Cfq" firstAttribute="top" secondItem="278-WB-2Bw" secondAttribute="bottom" constant="20" id="BOa-Fx-hp1"/>
<constraint firstItem="ZqB-cG-tej" firstAttribute="top" secondItem="dlT-JK-rdh" secondAttribute="bottom" constant="7" id="G6W-S7-Pf6"/>
<constraint firstAttribute="trailing" secondItem="ZqB-cG-tej" secondAttribute="trailing" id="TEl-qU-kUc"/>
<constraint firstItem="dlT-JK-rdh" firstAttribute="top" secondItem="MNz-CB-1bu" secondAttribute="bottom" id="bCx-3g-jk0"/>
<constraint firstItem="dlT-JK-rdh" firstAttribute="leading" secondItem="dAH-1v-C8c" secondAttribute="leading" id="bOD-2L-O5g"/>
<constraint firstAttribute="trailing" secondItem="dlT-JK-rdh" secondAttribute="trailing" id="cc9-zg-GfR"/>
<constraint firstItem="278-WB-2Bw" firstAttribute="centerY" secondItem="dAH-1v-C8c" secondAttribute="centerY" constant="-10" id="fZz-mK-fOm"/>
<constraint firstItem="XrL-W5-Cfq" firstAttribute="centerX" secondItem="dAH-1v-C8c" secondAttribute="centerX" id="lWo-11-gTg"/>
<constraint firstItem="278-WB-2Bw" firstAttribute="centerX" secondItem="dAH-1v-C8c" secondAttribute="centerX" id="r3U-km-MwH"/>
<constraint firstItem="ZqB-cG-tej" firstAttribute="leading" secondItem="dAH-1v-C8c" secondAttribute="leading" id="r4N-2j-4L9"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="Ex9-Kl-8KY"/>
Expand All @@ -71,7 +50,26 @@
</objects>
<point key="canvasLocation" x="572" y="331"/>
</scene>
<!--Remote Images Example View Controller-->
<!--Local Images Example-->
<scene sceneID="aBg-CO-ens">
<objects>
<viewController id="f8a-f0-vAF" customClass="LocalImagesExampleViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="lNl-qN-g2K"/>
<viewControllerLayoutGuide type="bottom" id="SG8-jU-0UD"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="SaM-Zd-zno">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" title="Local Images Example" id="wcX-jc-uut"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Zkx-2m-EX9" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="947" y="169"/>
</scene>
<!--Remote Images Example-->
<scene sceneID="GQ0-Ap-c2s">
<objects>
<viewController id="pKL-aW-u4x" customClass="RemoteImagesExampleViewController" sceneMemberID="viewController">
Expand All @@ -84,10 +82,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" title="Remote Images Example" id="Kct-fL-WDC"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ThL-u2-5Ki" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="956" y="674"/>
<point key="canvasLocation" x="971" y="779"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="aXv-6r-vL3">
Expand Down
13 changes: 13 additions & 0 deletions Example/Application/RootViewController.h
@@ -0,0 +1,13 @@
//
// RootViewController.h
// PhotoBrowser
//
// Created by Moch Xiao on 5/15/16.
// Copyright © 2016 Moch Xiao. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
13 changes: 13 additions & 0 deletions Example/Application/RootViewController.m
@@ -0,0 +1,13 @@
//
// RootViewController.m
// PhotoBrowser
//
// Created by Moch Xiao on 5/15/16.
// Copyright © 2016 Moch Xiao. All rights reserved.
//

#import "RootViewController.h"

@implementation RootViewController

@end
62 changes: 49 additions & 13 deletions Example/LocalImagesExample/LocalImagesExampleViewController.m
Expand Up @@ -8,42 +8,78 @@

#import "LocalImagesExampleViewController.h"
#import "PBViewController.h"
#import "PBViewControllerDataSource.h"
#import "PBImageScrollerViewController.h"
#import "PBViewControllerDelegate.h"
#import "UIView+PBSnapshot.h"

@interface LocalImagesExampleViewController () <PBViewControllerDataSource, PBViewControllerDelegate>
@property (nonatomic, strong) NSArray *urls;
@property (nonatomic, strong) NSArray *frames;
@property (nonatomic, strong) NSArray *imageViews;
@end

@implementation LocalImagesExampleViewController

- (IBAction)showPhotoBrowser:(UIButton *)sender {
- (void)viewDidLoad {
[super viewDidLoad];

for (NSInteger index = 0; index < self.frames.count; ++index) {
UIImageView *imageView = [UIImageView new];
imageView.clipsToBounds = YES;
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.backgroundColor = [UIColor blackColor];
imageView.frame = [self.frames[index] CGRectValue];
imageView.tag = index;
imageView.userInteractionEnabled = YES;
NSString *imageName = [NSString stringWithFormat:@"%@", @(index + 1)];
imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"]];
[self.view addSubview:imageView];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapedImageView:)];
[imageView addGestureRecognizer:tap];
}
}

- (void)handleTapedImageView:(UITapGestureRecognizer *)sender {
[self _showPhotoBrowser:(UIImageView *)sender.view];
}

- (void)_showPhotoBrowser:(UIImageView *)sender {
PBViewController *pbViewController = [PBViewController new];
pbViewController.pb_dataSource = self;
pbViewController.pb_delegate = self;
pbViewController.pb_startPage = 2;
pbViewController.pb_startPage = sender.tag;
[self presentViewController:pbViewController animated:YES completion:nil];
}

- (NSArray *)frames {
NSValue *frame1 = [NSValue valueWithCGRect:CGRectMake(20, 80, 80, 80)];
NSValue *frame2 = [NSValue valueWithCGRect:CGRectMake(110, 80, 120, 90)];
NSValue *frame3 = [NSValue valueWithCGRect:CGRectMake(240, 90, 100, 85)];

NSValue *frame4 = [NSValue valueWithCGRect:CGRectMake(20, 180, 75, 110)];
NSValue *frame5 = [NSValue valueWithCGRect:CGRectMake(110, 185, 150, 90)];
NSValue *frame6 = [NSValue valueWithCGRect:CGRectMake(270, 190, 100, 100)];

NSValue *frame7 = [NSValue valueWithCGRect:CGRectMake(20, 300, 90, 90)];
NSValue *frame8 = [NSValue valueWithCGRect:CGRectMake(120, 290, 120, 150)];
NSValue *frame9 = [NSValue valueWithCGRect:CGRectMake(250, 305, 100, 100)];

NSValue *frame10 = [NSValue valueWithCGRect:CGRectMake(120, 470, 120, 100)];

return @[frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9, frame10];
}

#pragma mark - PBViewControllerDataSource

- (NSInteger)numberOfPagesInViewController:(PBViewController *)viewController {
return 9;
return self.frames.count;
}

- (UIImage *)viewController:(PBViewController *)viewController imageForPageAtIndex:(NSInteger)index {
NSString *name = [NSString stringWithFormat:@"%@.jpg", @(index+1)];
return [UIImage imageNamed:name];
return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[@(index + 1) stringValue] ofType:@"jpg"]];
}

#pragma mark - PBViewControllerDelegate

- (void)viewController:(PBViewController *)viewController didSingleTapedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {
NSLog(@"didSingleTapedPageAtIndex: %@", @(index));
[viewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewController:(PBViewController *)viewController didLongPressedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {
NSLog(@"didLongPressedPageAtIndex: %@", @(index));
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ - (void)viewDidLoad {

- (void)handleDoubleTapAction: (UITapGestureRecognizer *)sender {
NSLog(@"~~~~~~~~~~~%s~~~~~~~~~~~", __FUNCTION__);
[self.imageScrollView _handleZoomForGestureRecognizer:sender];
// [self.imageScrollView _handleZoomForGestureRecognizer:sender];
}

- (void)dismiss {
Expand Down

0 comments on commit c930b8d

Please sign in to comment.