Add OS X example similar to the iOS example

This commit is contained in:
Michael Schneider
2016-01-06 15:03:44 +01:00
parent cd20716750
commit 2608291386
30 changed files with 1137 additions and 121 deletions

View File

@@ -8,6 +8,19 @@
/* Begin PBXBuildFile section */
42796FDA2C0B59B150630DA3 /* libPods-PINRemoteImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0141C54D0963FCEA0DB0381A /* libPods-PINRemoteImage.a */; };
9D9328C51C3C60E700E1F1D3 /* PINViewWithBackgroundColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328C41C3C60E700E1F1D3 /* PINViewWithBackgroundColor.m */; };
9D9328C91C3D09BB00E1F1D3 /* WebPViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328C71C3D09BB00E1F1D3 /* WebPViewController.m */; };
9D9328CA1C3D09BB00E1F1D3 /* WebPViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D9328C81C3D09BB00E1F1D3 /* WebPViewController.xib */; };
9D9328CF1C3D0C0D00E1F1D3 /* ScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328CD1C3D0C0D00E1F1D3 /* ScrollViewController.m */; };
9D9328D01C3D0C0D00E1F1D3 /* ScrollViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D9328CE1C3D0C0D00E1F1D3 /* ScrollViewController.xib */; };
9D9328D41C3D131900E1F1D3 /* ProcessingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328D21C3D131900E1F1D3 /* ProcessingViewController.m */; };
9D9328D51C3D131900E1F1D3 /* ProcessingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D9328D31C3D131900E1F1D3 /* ProcessingViewController.xib */; };
9D9328D91C3D243A00E1F1D3 /* ProgressiveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328D71C3D243A00E1F1D3 /* ProgressiveViewController.m */; };
9D9328DA1C3D243A00E1F1D3 /* ProgressiveViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D9328D81C3D243A00E1F1D3 /* ProgressiveViewController.xib */; };
9D9328DE1C3D275D00E1F1D3 /* DegradedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328DC1C3D275D00E1F1D3 /* DegradedViewController.m */; };
9D9328DF1C3D275D00E1F1D3 /* DegradedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D9328DD1C3D275D00E1F1D3 /* DegradedViewController.xib */; };
9D9328E21C3D489400E1F1D3 /* Kitten.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328E11C3D489400E1F1D3 /* Kitten.m */; };
9D97D09D1C3C4D960006C115 /* PINImageCollectionViewItemView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D97D09B1C3C4D960006C115 /* PINImageCollectionViewItemView.xib */; };
9DC09DB81C39AB0D00C6451E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DC09DB71C39AB0D00C6451E /* AppDelegate.m */; };
9DC09DBB1C39AB0D00C6451E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DC09DBA1C39AB0D00C6451E /* main.m */; };
9DC09DBD1C39AB0D00C6451E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9DC09DBC1C39AB0D00C6451E /* Assets.xcassets */; };
@@ -28,6 +41,26 @@
/* Begin PBXFileReference section */
0141C54D0963FCEA0DB0381A /* libPods-PINRemoteImage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PINRemoteImage.a"; sourceTree = BUILT_PRODUCTS_DIR; };
0C7B3B480ECE116693899B73 /* Pods-PINRemoteImage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PINRemoteImage.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PINRemoteImage/Pods-PINRemoteImage.debug.xcconfig"; sourceTree = "<group>"; };
9D9328C31C3C60E700E1F1D3 /* PINViewWithBackgroundColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PINViewWithBackgroundColor.h; sourceTree = "<group>"; };
9D9328C41C3C60E700E1F1D3 /* PINViewWithBackgroundColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PINViewWithBackgroundColor.m; sourceTree = "<group>"; };
9D9328C61C3D09BB00E1F1D3 /* WebPViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPViewController.h; sourceTree = "<group>"; };
9D9328C71C3D09BB00E1F1D3 /* WebPViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebPViewController.m; sourceTree = "<group>"; };
9D9328C81C3D09BB00E1F1D3 /* WebPViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WebPViewController.xib; sourceTree = "<group>"; };
9D9328CC1C3D0C0D00E1F1D3 /* ScrollViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollViewController.h; sourceTree = "<group>"; };
9D9328CD1C3D0C0D00E1F1D3 /* ScrollViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScrollViewController.m; sourceTree = "<group>"; };
9D9328CE1C3D0C0D00E1F1D3 /* ScrollViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ScrollViewController.xib; sourceTree = "<group>"; };
9D9328D11C3D131900E1F1D3 /* ProcessingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessingViewController.h; sourceTree = "<group>"; };
9D9328D21C3D131900E1F1D3 /* ProcessingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProcessingViewController.m; sourceTree = "<group>"; };
9D9328D31C3D131900E1F1D3 /* ProcessingViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ProcessingViewController.xib; sourceTree = "<group>"; };
9D9328D61C3D243A00E1F1D3 /* ProgressiveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProgressiveViewController.h; sourceTree = "<group>"; };
9D9328D71C3D243A00E1F1D3 /* ProgressiveViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProgressiveViewController.m; sourceTree = "<group>"; };
9D9328D81C3D243A00E1F1D3 /* ProgressiveViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ProgressiveViewController.xib; sourceTree = "<group>"; };
9D9328DB1C3D275D00E1F1D3 /* DegradedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DegradedViewController.h; sourceTree = "<group>"; };
9D9328DC1C3D275D00E1F1D3 /* DegradedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DegradedViewController.m; sourceTree = "<group>"; };
9D9328DD1C3D275D00E1F1D3 /* DegradedViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DegradedViewController.xib; sourceTree = "<group>"; };
9D9328E01C3D489400E1F1D3 /* Kitten.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Kitten.h; path = "../../Example-Shared/Kitten.h"; sourceTree = "<group>"; };
9D9328E11C3D489400E1F1D3 /* Kitten.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Kitten.m; path = "../../Example-Shared/Kitten.m"; sourceTree = "<group>"; };
9D97D09C1C3C4D960006C115 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PINImageCollectionViewItemView.xib; sourceTree = "<group>"; };
9DC09DB31C39AB0D00C6451E /* PINRemoteImage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PINRemoteImage.app; sourceTree = BUILT_PRODUCTS_DIR; };
9DC09DB61C39AB0D00C6451E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
9DC09DB71C39AB0D00C6451E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -68,6 +101,16 @@
name = Frameworks;
sourceTree = "<group>";
};
9D9328CB1C3D09BE00E1F1D3 /* Views */ = {
isa = PBXGroup;
children = (
9D97D09B1C3C4D960006C115 /* PINImageCollectionViewItemView.xib */,
9D9328C31C3C60E700E1F1D3 /* PINViewWithBackgroundColor.h */,
9D9328C41C3C60E700E1F1D3 /* PINViewWithBackgroundColor.m */,
);
name = Views;
sourceTree = "<group>";
};
9DC09DAA1C39AB0D00C6451E = {
isa = PBXGroup;
children = (
@@ -91,12 +134,29 @@
9DC09DB51C39AB0D00C6451E /* PINRemoteImage */ = {
isa = PBXGroup;
children = (
9DC09DB91C39AB0D00C6451E /* Supporting Files */,
9D9328CB1C3D09BE00E1F1D3 /* Views */,
9D9328E01C3D489400E1F1D3 /* Kitten.h */,
9D9328E11C3D489400E1F1D3 /* Kitten.m */,
9DC09DB61C39AB0D00C6451E /* AppDelegate.h */,
9DC09DB71C39AB0D00C6451E /* AppDelegate.m */,
9DC09DBC1C39AB0D00C6451E /* Assets.xcassets */,
9DC09DBE1C39AB0D00C6451E /* MainMenu.xib */,
9DC09DC11C39AB0D00C6451E /* Info.plist */,
9DC09DB91C39AB0D00C6451E /* Supporting Files */,
9D9328CC1C3D0C0D00E1F1D3 /* ScrollViewController.h */,
9D9328CD1C3D0C0D00E1F1D3 /* ScrollViewController.m */,
9D9328CE1C3D0C0D00E1F1D3 /* ScrollViewController.xib */,
9D9328C61C3D09BB00E1F1D3 /* WebPViewController.h */,
9D9328C71C3D09BB00E1F1D3 /* WebPViewController.m */,
9D9328C81C3D09BB00E1F1D3 /* WebPViewController.xib */,
9D9328D61C3D243A00E1F1D3 /* ProgressiveViewController.h */,
9D9328D71C3D243A00E1F1D3 /* ProgressiveViewController.m */,
9D9328D81C3D243A00E1F1D3 /* ProgressiveViewController.xib */,
9D9328DB1C3D275D00E1F1D3 /* DegradedViewController.h */,
9D9328DC1C3D275D00E1F1D3 /* DegradedViewController.m */,
9D9328DD1C3D275D00E1F1D3 /* DegradedViewController.xib */,
9D9328D11C3D131900E1F1D3 /* ProcessingViewController.h */,
9D9328D21C3D131900E1F1D3 /* ProcessingViewController.m */,
9D9328D31C3D131900E1F1D3 /* ProcessingViewController.xib */,
);
path = PINRemoteImage;
sourceTree = "<group>";
@@ -104,6 +164,7 @@
9DC09DB91C39AB0D00C6451E /* Supporting Files */ = {
isa = PBXGroup;
children = (
9DC09DBC1C39AB0D00C6451E /* Assets.xcassets */,
9DC09DBA1C39AB0D00C6451E /* main.m */,
);
name = "Supporting Files";
@@ -211,7 +272,13 @@
buildActionMask = 2147483647;
files = (
9DC09DBD1C39AB0D00C6451E /* Assets.xcassets in Resources */,
9D9328DA1C3D243A00E1F1D3 /* ProgressiveViewController.xib in Resources */,
9D9328DF1C3D275D00E1F1D3 /* DegradedViewController.xib in Resources */,
9D9328CA1C3D09BB00E1F1D3 /* WebPViewController.xib in Resources */,
9D9328D01C3D0C0D00E1F1D3 /* ScrollViewController.xib in Resources */,
9D97D09D1C3C4D960006C115 /* PINImageCollectionViewItemView.xib in Resources */,
9DC09DC01C39AB0D00C6451E /* MainMenu.xib in Resources */,
9D9328D51C3D131900E1F1D3 /* ProcessingViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -277,8 +344,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9D9328CF1C3D0C0D00E1F1D3 /* ScrollViewController.m in Sources */,
9D9328C91C3D09BB00E1F1D3 /* WebPViewController.m in Sources */,
9D9328E21C3D489400E1F1D3 /* Kitten.m in Sources */,
9D9328DE1C3D275D00E1F1D3 /* DegradedViewController.m in Sources */,
9DC09DBB1C39AB0D00C6451E /* main.m in Sources */,
9D9328D41C3D131900E1F1D3 /* ProcessingViewController.m in Sources */,
9D9328D91C3D243A00E1F1D3 /* ProgressiveViewController.m in Sources */,
9DC09DB81C39AB0D00C6451E /* AppDelegate.m in Sources */,
9D9328C51C3C60E700E1F1D3 /* PINViewWithBackgroundColor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -301,6 +375,14 @@
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
9D97D09B1C3C4D960006C115 /* PINImageCollectionViewItemView.xib */ = {
isa = PBXVariantGroup;
children = (
9D97D09C1C3C4D960006C115 /* Base */,
);
name = PINImageCollectionViewItemView.xib;
sourceTree = "<group>";
};
9DC09DBE1C39AB0D00C6451E /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (

View File

@@ -7,25 +7,91 @@
//
#import "AppDelegate.h"
#import <PINRemoteImage/PINRemoteImageManager.h>
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
#import <PINCache/PINCache.h>
#import "ScrollViewController.h"
#import "WebPViewController.h"
#import "DegradedViewController.h"
#import "ProgressiveViewController.h"
#import "ProcessingViewController.h"
enum : NSUInteger {
kScrollViewControllerSegment = 0,
kWebPViewControllerSegment,
kProgressiveViewControllerSegment,
kDegradedViewControllerSegment,
kProcessingViewControllerSegment,
};
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSImageView *imageView;
@property (weak) IBOutlet NSSegmentedControl *segmentedControl;
@property (nonatomic, strong) NSViewController *currentViewController;
@property (nonatomic, copy, readonly) NSDictionary *viewControllerMapping;
@property (nonatomic, strong) NSMutableDictionary *viewControllerCache;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSURL *imageURL = [NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/92/5d/5a/925d5ac74db0dcfabc238e1686e31d16.jpg"];
[self.imageView pin_setImageFromURL:imageURL];
#pragma mark - NSNibAwakening
- (void)awakeFromNib
{
[super awakeFromNib];
self.window.titleVisibility = NSWindowTitleHidden;
self.segmentedControl.selectedSegment = 0;
self.viewControllerCache = [NSMutableDictionary dictionary];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
#pragma mark - NSApplicationDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self segmentedControlChanged:self.segmentedControl];
}
@end
#pragma mark - Mapping
- (NSDictionary *)viewControllerMapping
{
static NSDictionary *mapping = nil;
if (mapping == nil) {
mapping = @{
@(kScrollViewControllerSegment) : [ScrollViewController class],
@(kWebPViewControllerSegment) : [WebPViewController class],
@(kProgressiveViewControllerSegment) : [ProgressiveViewController class],
@(kDegradedViewControllerSegment) : [DegradedViewController class],
@(kProcessingViewControllerSegment) : [ProcessingViewController class]
};
}
return [mapping copy];
}
#pragma mark - Actions
- (IBAction)segmentedControlChanged:(NSSegmentedControl *)segmentedControl
{
[self.currentViewController.view removeFromSuperview];
NSInteger selectedSegment = segmentedControl.selectedSegment;
NSViewController *viewController = self.viewControllerCache[@(selectedSegment)];
if (viewController == nil) {
viewController = [self.viewControllerMapping[@(selectedSegment)] new];
viewController.view.autoresizingMask = NSViewHeightSizable | NSViewWidthSizable;
self.viewControllerCache[@(selectedSegment)] = viewController;
}
self.currentViewController = viewController;
self.currentViewController.view.frame = self.window.contentView.bounds;
[self.window.contentView addSubview:self.currentViewController.view];
}
@end

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "white-pinterest-logo@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "white-pinterest-logo@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -14,7 +14,7 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="imageView" destination="8gg-pX-qsH" id="lOM-EA-FN2"/>
<outlet property="segmentedControl" destination="RO4-iv-KcU" id="3m9-j1-OdP"/>
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
</connections>
</customObject>
@@ -669,21 +669,54 @@
</items>
</menu>
<window title="PINRemoteImage" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" unifiedTitleAndToolbar="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="800"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8gg-pX-qsH">
<rect key="frame" x="20" y="181" width="203" height="159"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="fvV-gK-nH1"/>
</imageView>
</subviews>
</view>
<point key="canvasLocation" x="306" y="347"/>
<toolbar key="toolbar" implicitIdentifier="ECE89FB8-3803-4EC1-80FA-A3A31DB0B167" autosavesConfiguration="NO" displayMode="iconAndLabel" sizeMode="regular" id="uDT-d9-ekb">
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="NSToolbarShowColorsItem" id="aif-PT-Dq9"/>
<toolbarItem implicitItemIdentifier="NSToolbarShowFontsItem" id="K2B-bl-MIL"/>
<toolbarItem implicitItemIdentifier="NSToolbarPrintItem" id="M0s-cg-TFk"/>
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="tTN-Ln-qcZ"/>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="yrG-z8-rb5"/>
<toolbarItem implicitItemIdentifier="94242F95-D4DC-435D-858C-7820289981E0" label="Switch Views" paletteLabel="Switch Views" id="hxg-fF-Cdm">
<nil key="toolTip"/>
<size key="minSize" width="104" height="24"/>
<size key="maxSize" width="300" height="26"/>
<segmentedControl key="view" verticalHuggingPriority="750" id="RO4-iv-KcU">
<rect key="frame" x="0.0" y="14" width="300" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="texturedSquare" trackingMode="selectOne" id="jqk-9E-gyT">
<font key="font" metaFont="system"/>
<segments>
<segment label="Scroll"/>
<segment label="WebP" selected="YES" tag="1"/>
<segment label="Progressive"/>
<segment label="Degraded"/>
<segment label="Processing"/>
</segments>
</segmentedCell>
<connections>
<action selector="segmentedControlChanged:" target="Voe-Tx-rLC" id="3Bi-fi-jgj"/>
</connections>
</segmentedControl>
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="yrG-z8-rb5"/>
<toolbarItem reference="hxg-fF-Cdm"/>
<toolbarItem reference="yrG-z8-rb5"/>
</defaultToolbarItems>
</toolbar>
<connections>
<outlet property="delegate" destination="Voe-Tx-rLC" id="f1w-qE-xB0"/>
</connections>
<point key="canvasLocation" x="248" y="320"/>
</window>
</objects>
</document>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="c22-O7-iKe" customClass="PINViewWithBackgroundColor">
<rect key="frame" x="0.0" y="0.0" width="315" height="57"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="E10-Mq-XwT">
<rect key="frame" x="0.0" y="0.0" width="315" height="57"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="gDg-Yh-UMg"/>
</imageView>
</subviews>
<point key="canvasLocation" x="218.5" y="-211.5"/>
</customView>
<collectionViewItem id="MV8-a4-2cg" customClass="PINImageCollectionViewItem">
<connections>
<outlet property="imageView" destination="E10-Mq-XwT" id="Tip-e9-98q"/>
<outlet property="view" destination="c22-O7-iKe" id="5un-fQ-wz5"/>
</connections>
</collectionViewItem>
</objects>
</document>

View File

@@ -0,0 +1,13 @@
//
// DegradedViewController.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface DegradedViewController : NSViewController
@end

View File

@@ -0,0 +1,48 @@
//
// DegradedViewController.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "DegradedViewController.h"
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
@interface DegradedViewController ()
@property (weak) IBOutlet NSImageView *imageView;
@end
@implementation DegradedViewController
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super initWithNibName:NSStringFromClass(self.class) bundle:nil];
if (self == nil) { return self; }
return self;
}
#pragma mark - NSViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[PINRemoteImageManager sharedImageManager] setShouldUpgradeLowQualityImages:YES completion:nil];
}
- (void)viewWillAppear
{
[super viewWillAppear];
[self.imageView pin_setImageFromURLs:@[[NSURL URLWithString:@"https://placekitten.com/101/101"],
[NSURL URLWithString:@"https://placekitten.com/401/401"],
[NSURL URLWithString:@"https://placekitten.com/801/801"]]];
}
@end

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="DegradedViewController">
<connections>
<outlet property="imageView" destination="tCB-5K-cS5" id="o6E-MQ-Zn4"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="tCB-5K-cS5">
<rect key="frame" x="0.0" y="20" width="480" height="207"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="1Wg-r1-lR4"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="t3s-uL-GUc">
<rect key="frame" x="-2" y="235" width="484" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="center" title="Enable Network Link Conditioner" id="gUY-gj-zGt">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</customView>
</objects>
</document>

View File

@@ -0,0 +1,15 @@
//
// PINViewWithBackgroundColor.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/5/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface PINViewWithBackgroundColor : NSView
@property (nonatomic, strong) NSColor *backgroundColor;
@end

View File

@@ -0,0 +1,50 @@
//
// PINViewWithBackgroundColor.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/5/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "PINViewWithBackgroundColor.h"
@implementation PINViewWithBackgroundColor
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super init];
if (self == nil) { return self; }
[self initPINViewWithBackgroundColor];
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self == nil) { return self; }
[self initPINViewWithBackgroundColor];
return self;
}
- (void)initPINViewWithBackgroundColor
{
}
#pragma mark - Drawing
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
if (self.backgroundColor != nil) {
[self.backgroundColor setFill];
NSRectFill(dirtyRect);
}
}
@end

View File

@@ -0,0 +1,13 @@
//
// ProcessingViewController.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface ProcessingViewController : NSViewController
@end

View File

@@ -0,0 +1,80 @@
//
// ProcessingViewController.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "ProcessingViewController.h"
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
#import <PINRemoteImage/PINImage+DecodedImage.h>
@interface ProcessingViewController ()
@property (weak) IBOutlet NSImageView *imageView;
@end
@implementation ProcessingViewController
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super initWithNibName:NSStringFromClass(self.class) bundle:nil];
if (self == nil) { return self; }
return self;
}
#pragma mark - NSViewController
- (void)viewWillAppear
{
[super viewWillAppear];
[self.imageView pin_setImageFromURL:[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/5b/c6/c5/5bc6c5387ff6f104fd642f2b375efba3.jpg"] processorKey:@"rounded" processor:^NSImage *(PINRemoteImageManagerResult *result, NSUInteger *cost)
{
NSImage *image = result.image;
CGFloat radius = 7.0f;
CGSize targetSize = CGSizeMake(200, 300);
CGRect imageRect = CGRectMake(0, 0, targetSize.width, targetSize.height);
NSImage *processedImage = [[NSImage alloc] initWithSize:targetSize];
[processedImage lockFocus];
NSBezierPath *bezierPath = [NSBezierPath bezierPathWithRoundedRect:imageRect xRadius:radius yRadius:radius];
[bezierPath addClip];
CGFloat widthMultiplier = targetSize.width / image.size.width;
CGFloat heightMultiplier = targetSize.height / image.size.height;
CGFloat sizeMultiplier = MAX(widthMultiplier, heightMultiplier);
CGRect drawRect = CGRectMake(0, 0, image.size.width * sizeMultiplier, image.size.height * sizeMultiplier);
if (CGRectGetMaxX(drawRect) > CGRectGetMaxX(imageRect)) {
drawRect.origin.x -= (CGRectGetMaxX(drawRect) - CGRectGetMaxX(imageRect)) / 2.0;
}
if (CGRectGetMaxY(drawRect) > CGRectGetMaxY(imageRect)) {
drawRect.origin.y -= (CGRectGetMaxY(drawRect) - CGRectGetMaxY(imageRect)) / 2.0;
}
[image drawInRect:drawRect];
[[NSColor redColor] setStroke];
[bezierPath setLineWidth:5.0];
[bezierPath stroke];
NSImage *logo = [NSImage imageNamed:@"white-pinterest-logo"];
CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
CGContextSetAlpha(ctx, 0.5);
CGContextDrawImage(ctx, CGRectMake(90, 10, logo.size.width, logo.size.height), [logo CGImage]);
[processedImage unlockFocus];
return processedImage;
}];
}
@end

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ProcessingViewController">
<connections>
<outlet property="imageView" destination="emk-Sz-TZg" id="Jgt-ru-uHG"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="emk-Sz-TZg">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="Ubd-0R-2Jx"/>
</imageView>
</subviews>
<point key="canvasLocation" x="288" y="186"/>
</customView>
</objects>
</document>

View File

@@ -0,0 +1,14 @@
//
// ProgressiveViewController.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface ProgressiveViewController : NSViewController
@end

View File

@@ -0,0 +1,60 @@
//
// ProgressiveViewController.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "ProgressiveViewController.h"
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
#import <PINCache/PINCache.h>
@interface ProgressiveViewController ()
@property (weak) IBOutlet NSImageView *imageView;
@end
@implementation ProgressiveViewController
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super initWithNibName:NSStringFromClass(self.class) bundle:nil];
if (self == nil) { return self; }
return self;
}
#pragma mark - NSViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// MUST BE SET ON IMAGE VIEW TO GET PROGRESS UPDATES!
self.imageView.pin_updateWithProgress = YES;
}
- (void)viewDidAppear
{
[super viewDidAppear];
NSURL *progressiveURL = [NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/1200x/2e/0c/c5/2e0cc5d86e7b7cd42af225c29f21c37f.jpg"];
[[PINRemoteImageManager sharedImageManager] setProgressThresholds:@[@(0.1), @(0.2), @(0.3), @(0.4), @(0.5), @(0.6), @(0.7), @(0.8), @(0.9)] completion:nil];
[[[PINRemoteImageManager sharedImageManager] cache] removeObjectForKey:[[PINRemoteImageManager sharedImageManager] cacheKeyForURL:progressiveURL processorKey:nil]];
[self.imageView pin_setImageFromURL:progressiveURL];
NSMutableArray *progress = [[NSMutableArray alloc] init];
[[PINRemoteImageManager sharedImageManager]
downloadImageWithURL:progressiveURL
options:PINRemoteImageManagerDownloadOptionsNone progress:^(PINRemoteImageManagerResult *result) {
[progress addObject:result.image];
} completion:^(PINRemoteImageManagerResult *result) {
[progress addObject:result.image];
}];
}
@end

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ProgressiveViewController">
<connections>
<outlet property="imageView" destination="uoW-RR-Xm0" id="DDC-WI-LKG"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="326"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="uoW-RR-Xm0">
<rect key="frame" x="0.0" y="20" width="480" height="261"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="Wdl-Kf-Ck0"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="otO-SQ-XPr">
<rect key="frame" x="-2" y="289" width="484" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="center" title="Enable Network Link Conditioner" id="1kd-sX-EdU">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<point key="canvasLocation" x="139" y="381"/>
</customView>
</objects>
</document>

View File

@@ -0,0 +1,13 @@
//
// ScrollViewController.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface ScrollViewController : NSViewController
@end

View File

@@ -0,0 +1,128 @@
//
// ScrollViewController.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "ScrollViewController.h"
#import <Quartz/Quartz.h>
#import <PINRemoteImage/PINRemoteImageManager.h>
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
#import <PINCache/PINCache.h>
#import "PINViewWithBackgroundColor.h"
#import "Kitten.h"
@interface PINImageCollectionViewItem : NSCollectionViewItem
@end
@interface ScrollViewController ()
@property (weak) IBOutlet NSCollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *kittens;
@end
@implementation ScrollViewController
#pragma mark - Lifecycle
- (instancetype)init
{
srand([[NSDate date] timeIntervalSince1970]);
self = [super initWithNibName:NSStringFromClass(self.class) bundle:nil];
if (self == nil) { return self; }
[[[PINRemoteImageManager sharedImageManager] cache] removeAllObjects];
return self;
}
#pragma mark - NSViewController
- (void)awakeFromNib
{
[super awakeFromNib];
[self.collectionView registerNib:[[NSNib alloc] initWithNibNamed:@"PINImageCollectionViewItemView" bundle:nil] forItemWithIdentifier:@"ItemIdentifier"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.kittens = [NSMutableArray new];
[self fetchKittenImages];
}
- (void)viewWillLayout
{
[super viewWillLayout];
[self.collectionView.collectionViewLayout invalidateLayout];
}
#pragma mark - Load images
- (void)fetchKittenImages
{
[Kitten fetchKittenForWidth:CGRectGetWidth(self.collectionView.frame) completion:^(NSArray *kittens) {
[self.kittens addObjectsFromArray:kittens];
[self.collectionView reloadData];
}];
}
#pragma mark - <NSCollectionViewDataSource, NSCollectionViewDelegate>
- (NSInteger)collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.kittens.count;
}
- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
{
PINImageCollectionViewItem *item = [collectionView makeItemWithIdentifier:@"PINImageCollectionViewItemView" forIndexPath:indexPath];
Kitten *kitten = [self.kittens objectAtIndex:indexPath.item];
item.imageView.alphaValue = 0.0f;
__weak NSCollectionViewItem *weakItem = item;
[item.imageView pin_setImageFromURL:kitten.imageURL
completion:^(PINRemoteImageManagerResult *result) {
if (result.requestDuration > 0.25) {
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
context.duration = 0.3;
context.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
weakItem.imageView.animator.alphaValue = 1.0f;
} completionHandler:^{
}];
} else {
weakItem.imageView.alphaValue = 1.0f;
}
}];
return item;
}
- (NSSize)collectionView:(NSCollectionView *)collectionView layout:(NSCollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
Kitten *kitten = [self.kittens objectAtIndex:indexPath.item];
return NSMakeSize(CGRectGetWidth(collectionView.frame), kitten.imageSize.height);
}
@end
@implementation PINImageCollectionViewItem
- (void)prepareForReuse
{
[super prepareForReuse];
self.imageView.image = nil;
}
@end

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ScrollViewController">
<connections>
<outlet property="collectionView" destination="ogM-uZ-bd2" id="KGM-OB-i3t"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="597" height="488"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="CVA-mr-GZz">
<rect key="frame" x="0.0" y="0.0" width="597" height="488"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="BlF-Pn-SSe">
<rect key="frame" x="0.0" y="0.0" width="597" height="488"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView id="ogM-uZ-bd2">
<rect key="frame" x="0.0" y="0.0" width="597" height="488"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="hTh-pm-rIJ">
<size key="itemSize" width="50" height="50"/>
</collectionViewFlowLayout>
<color key="primaryBackgroundColor" white="1" alpha="0.0" colorSpace="deviceWhite"/>
<connections>
<outlet property="dataSource" destination="-2" id="SHw-gT-fSR"/>
<outlet property="delegate" destination="-2" id="1bf-S7-Ti5"/>
</connections>
</collectionView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="yCF-P6-I1S">
<rect key="frame" x="1" y="144" width="233" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="BD2-zt-Lum">
<rect key="frame" x="234" y="1" width="15" height="143"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
<point key="canvasLocation" x="231.5" y="310"/>
</customView>
</objects>
</document>

View File

@@ -0,0 +1,13 @@
//
// WebPViewController.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface WebPViewController : NSViewController
@end

View File

@@ -0,0 +1,38 @@
//
// WebPViewController.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "WebPViewController.h"
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
@interface WebPViewController ()
@property (weak) IBOutlet NSImageView *imageView;
@end
@implementation WebPViewController
#pragma mark - Lifecycle
- (instancetype)init
{
self = [super initWithNibName:NSStringFromClass(self.class) bundle:nil];
if (self == nil) { return self; }
return self;
}
#pragma mark - NSViewController
- (void)viewDidAppear
{
[super viewDidAppear];
[self.imageView pin_setImageFromURL:[NSURL URLWithString:@"https://github.com/samdutton/simpl/blob/master/picturetype/kittens.webp?raw=true"]];
}
@end

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="WebPViewController">
<connections>
<outlet property="imageView" destination="FBS-1p-Ron" id="tcq-oE-2jh"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="FBS-1p-Ron">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="IxE-x7-3Mk"/>
</imageView>
</subviews>
<point key="canvasLocation" x="304" y="319"/>
</customView>
</objects>
</document>

23
Example-Shared/Kitten.h Normal file
View File

@@ -0,0 +1,23 @@
//
// Kitten.h
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#endif
@interface Kitten : NSObject
@property (nonatomic, strong) NSURL *imageURL;
@property (nonatomic, strong) id dominantColor;
@property (nonatomic, assign) CGSize imageSize;
+ (void)fetchKittenForWidth:(CGFloat)width completion:(void (^)(NSArray *kittens))completion;
@end

132
Example-Shared/Kitten.m Normal file
View File

@@ -0,0 +1,132 @@
//
// Kitten.m
// PINRemoteImage
//
// Created by Michael Schneider on 1/6/16.
// Copyright © 2016 mischneider. All rights reserved.
//
#import "Kitten.h"
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
@interface NSValue (PINiOSMapping)
+ (NSValue *)valueWithCGSize:(CGSize)size;
- (CGSize)CGSizeValue;
@end
@implementation NSValue (PINiOSMapping)
+ (NSValue *)valueWithCGSize:(CGSize)size
{
return [self valueWithSize:size];
}
- (CGSize)CGSizeValue
{
return self.sizeValue;
}
@end
#endif
@implementation Kitten
+ (void)fetchKittenForWidth:(CGFloat)width completion:(void (^)(NSArray *kittens))completion
{
NSArray *kittenURLs = @[[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/92/5d/5a/925d5ac74db0dcfabc238e1686e31d16.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/ff/b3/ae/ffb3ae40533b7f9463cf1c04d7ab69d1.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/e4/b7/7c/e4b77ca06e1d4a401b1a49d7fadd90d9.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/46/e1/59/46e159d76b167ed9211d662f95e7bf6f.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/7a/72/77/7a72779329942c06f888c148eb8d7e34.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/60/21/8f/60218ff43257fb3b6d7c5b888f74a5bf.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/90/e8/e4/90e8e47d53e71e0d97691dd13a5617fb.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/96/ae/31/96ae31fbc52d96dd3308d2754a6ca37e.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/9b/7b/99/9b7b99ff63be31bba8f9863724b3ebbc.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/80/23/51/802351d953dd2a8b232d0da1c7ca6880.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/f5/c4/f0/f5c4f04fa2686338dc3b08420d198484.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/2b/06/4f/2b064f3e0af984a556ac94b251ff7060.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/17/1f/c0/171fc02398143269d8a507a15563166a.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/8a/35/33/8a35338bbf67c86a198ba2dd926edd82.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/4d/6e/3c/4d6e3cf970031116c57486e85c2a4cab.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/54/25/ee/5425eeccba78731cf7be70f0b8808bd2.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/04/f1/3f/04f13fdb7580dcbe8c4d6b7d5a0a5ec2.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/dc/16/4e/dc164ed33af9d899e5ed188e642f00e9.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/c1/06/13/c106132936189b6cb654671f2a2183ed.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/46/43/ed/4643eda4e1be4273721a76a370b90346.jpg"],
];
NSArray *kittenSizes = @[[NSValue valueWithCGSize:CGSizeMake(503, 992)],
[NSValue valueWithCGSize:CGSizeMake(500, 337)],
[NSValue valueWithCGSize:CGSizeMake(522, 695)],
[NSValue valueWithCGSize:CGSizeMake(557, 749)],
[NSValue valueWithCGSize:CGSizeMake(710, 1069)],
[NSValue valueWithCGSize:CGSizeMake(522, 676)],
[NSValue valueWithCGSize:CGSizeMake(500, 688)],
[NSValue valueWithCGSize:CGSizeMake(377, 700)],
[NSValue valueWithCGSize:CGSizeMake(334, 494)],
[NSValue valueWithCGSize:CGSizeMake(625, 469)],
[NSValue valueWithCGSize:CGSizeMake(625, 833)],
[NSValue valueWithCGSize:CGSizeMake(625, 469)],
[NSValue valueWithCGSize:CGSizeMake(625, 469)],
[NSValue valueWithCGSize:CGSizeMake(625, 791)],
[NSValue valueWithCGSize:CGSizeMake(625, 833)],
[NSValue valueWithCGSize:CGSizeMake(605, 605)],
[NSValue valueWithCGSize:CGSizeMake(504, 750)],
[NSValue valueWithCGSize:CGSizeMake(500, 500)],
[NSValue valueWithCGSize:CGSizeMake(640, 640)],
[NSValue valueWithCGSize:CGSizeMake(500, 473)],
];
dispatch_group_t group = dispatch_group_create();
NSMutableArray *kittens = [[NSMutableArray alloc] init];
CGFloat scale = 1;
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
scale = [[UIScreen mainScreen] scale];
#else
scale = [[NSScreen mainScreen] backingScaleFactor];
#endif
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSInteger count = 0;
for (NSInteger idx = 0; idx < 500; idx++) {
Kitten *kitten = [[Kitten alloc] init];
CGFloat r = (rand() % 255) / 255.0f;
CGFloat g = (rand() % 255) / 255.0f;
CGFloat b = (rand() % 255) / 255.0f;
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
kitten.dominantColor = [UIColor colorWithRed:r green:g blue:b alpha:1.0f];
#else
kitten.dominantColor = [NSColor colorWithRed:r green:g blue:b alpha:1.0f];
#endif
NSUInteger kittenIdx = rand() % 20;
CGSize kittenSize = [kittenSizes[kittenIdx] CGSizeValue];
NSInteger kittenSizeWidth = kittenSize.width;
NSInteger kittenSizeHeight = kittenSize.height;
if (kittenSizeWidth > (width * scale)) {
kittenSizeHeight = ((width * scale) / kittenSizeWidth) * kittenSizeHeight;
kittenSizeWidth = (width * scale);
}
kitten.imageURL = kittenURLs[kittenIdx];
kitten.imageSize = CGSizeMake(kittenSizeWidth / scale, kittenSizeHeight / scale);
dispatch_sync(dispatch_get_main_queue(), ^{
[kittens addObject:kitten];
});
count++;
}
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
if (completion) {
completion(kittens);
}
});
}
@end

View File

@@ -24,6 +24,7 @@
68B3850B1B5572BF004EB26F /* ProgressiveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 68B3850A1B5572BF004EB26F /* ProgressiveViewController.m */; };
68B3850E1B5577D4004EB26F /* DegradedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 68B3850D1B5577D4004EB26F /* DegradedViewController.m */; };
68B5CDF21A0BEC8C00A4BAAC /* PINRemoteImage_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68B5CDF11A0BEC8C00A4BAAC /* PINRemoteImage_Tests.m */; };
9D9328E51C3D4CC200E1F1D3 /* Kitten.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9328E41C3D4CC200E1F1D3 /* Kitten.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -73,6 +74,8 @@
804862496DA4D87612F805CC /* Pods-PINRemoteImage Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PINRemoteImage Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PINRemoteImage Tests/Pods-PINRemoteImage Tests.release.xcconfig"; sourceTree = "<group>"; };
855F72A0CF3949DB873DBBC8 /* libPods-PIRemoteImage Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PIRemoteImage Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
8FEF8351C6C35A80F5E99B0E /* Pods-PINRemoteImage.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PINRemoteImage.release.xcconfig"; path = "Pods/Target Support Files/Pods-PINRemoteImage/Pods-PINRemoteImage.release.xcconfig"; sourceTree = "<group>"; };
9D9328E31C3D4CC200E1F1D3 /* Kitten.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Kitten.h; path = "../../Example-Shared/Kitten.h"; sourceTree = "<group>"; };
9D9328E41C3D4CC200E1F1D3 /* Kitten.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Kitten.m; path = "../../Example-Shared/Kitten.m"; sourceTree = "<group>"; };
A5DEC9B706184109844D57E2 /* PINRemoteImage.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = PINRemoteImage.podspec; path = ../PINRemoteImage.podspec; sourceTree = "<group>"; };
BA758DBC0C76C8C8804BFDEA /* Pods-PINRemoteImage Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PINRemoteImage Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PINRemoteImage Tests/Pods-PINRemoteImage Tests.debug.xcconfig"; sourceTree = "<group>"; };
CF9B14D6B6E747C0BEB340CF /* libPods-PIRemoteImage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PIRemoteImage.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -143,6 +146,8 @@
6003F593195388D20070C39A /* PINRemoteImage */ = {
isa = PBXGroup;
children = (
9D9328E31C3D4CC200E1F1D3 /* Kitten.h */,
9D9328E41C3D4CC200E1F1D3 /* Kitten.m */,
6003F59C195388D20070C39A /* PINAppDelegate.h */,
6003F59D195388D20070C39A /* PINAppDelegate.m */,
6003F59F195388D20070C39A /* Main.storyboard */,
@@ -228,6 +233,7 @@
6003F587195388D20070C39A /* Frameworks */,
6003F588195388D20070C39A /* Resources */,
976369F3155C4085B1D6B257 /* Copy Pods Resources */,
EFEDFBF4E4735EB12D724CCB /* Embed Pods Frameworks */,
);
buildRules = (
);
@@ -247,6 +253,7 @@
68B5CDEA1A0BEC8C00A4BAAC /* Frameworks */,
68B5CDEB1A0BEC8C00A4BAAC /* Resources */,
82957B3C29244E2585DE33E5 /* Copy Pods Resources */,
977208AB9235B89CD698BADB /* Embed Pods Frameworks */,
);
buildRules = (
);
@@ -360,6 +367,21 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PINRemoteImage/Pods-PINRemoteImage-resources.sh\"\n";
showEnvVarsInLog = 0;
};
977208AB9235B89CD698BADB /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PINRemoteImage Tests/Pods-PINRemoteImage Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
C18578E9FCCC4A349D17591E /* Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -375,6 +397,21 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
EFEDFBF4E4735EB12D724CCB /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PINRemoteImage/Pods-PINRemoteImage-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -384,6 +421,7 @@
files = (
68B385081B557116004EB26F /* WebPViewController.m in Sources */,
68B3850B1B5572BF004EB26F /* ProgressiveViewController.m in Sources */,
9D9328E51C3D4CC200E1F1D3 /* Kitten.m in Sources */,
6003F59E195388D20070C39A /* PINAppDelegate.m in Sources */,
682C52611B584DD300B3B813 /* ProcessingViewController.m in Sources */,
6003F5A7195388D20070C39A /* PINViewController.m in Sources */,

View File

@@ -59,6 +59,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {

View File

@@ -15,6 +15,8 @@
#import <FLAnimatedImage/FLAnimatedImageView.h>
#endif
#import "Kitten.h"
@interface PINViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@@ -28,14 +30,6 @@
@end
@interface Kitten : NSObject
@property (nonatomic, strong) NSURL *imageURL;
@property (nonatomic, strong) UIColor *dominantColor;
@property (nonatomic, assign) CGSize imageSize;
@end
@implementation PINViewController
- (instancetype)initWithCoder:(NSCoder *)aDecoder
@@ -47,89 +41,12 @@
return self;
}
- (void)addImages
- (void)fetchKittenImages
{
NSArray *kittenURLs = @[[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/92/5d/5a/925d5ac74db0dcfabc238e1686e31d16.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/ff/b3/ae/ffb3ae40533b7f9463cf1c04d7ab69d1.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/e4/b7/7c/e4b77ca06e1d4a401b1a49d7fadd90d9.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/46/e1/59/46e159d76b167ed9211d662f95e7bf6f.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/7a/72/77/7a72779329942c06f888c148eb8d7e34.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/60/21/8f/60218ff43257fb3b6d7c5b888f74a5bf.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/90/e8/e4/90e8e47d53e71e0d97691dd13a5617fb.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/96/ae/31/96ae31fbc52d96dd3308d2754a6ca37e.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/9b/7b/99/9b7b99ff63be31bba8f9863724b3ebbc.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/80/23/51/802351d953dd2a8b232d0da1c7ca6880.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/f5/c4/f0/f5c4f04fa2686338dc3b08420d198484.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/2b/06/4f/2b064f3e0af984a556ac94b251ff7060.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/17/1f/c0/171fc02398143269d8a507a15563166a.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/8a/35/33/8a35338bbf67c86a198ba2dd926edd82.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/4d/6e/3c/4d6e3cf970031116c57486e85c2a4cab.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/54/25/ee/5425eeccba78731cf7be70f0b8808bd2.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/04/f1/3f/04f13fdb7580dcbe8c4d6b7d5a0a5ec2.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/dc/16/4e/dc164ed33af9d899e5ed188e642f00e9.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/c1/06/13/c106132936189b6cb654671f2a2183ed.jpg"],
[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/46/43/ed/4643eda4e1be4273721a76a370b90346.jpg"],
];
NSArray *kittenSizes = @[[NSValue valueWithCGSize:CGSizeMake(503, 992)],
[NSValue valueWithCGSize:CGSizeMake(500, 337)],
[NSValue valueWithCGSize:CGSizeMake(522, 695)],
[NSValue valueWithCGSize:CGSizeMake(557, 749)],
[NSValue valueWithCGSize:CGSizeMake(710, 1069)],
[NSValue valueWithCGSize:CGSizeMake(522, 676)],
[NSValue valueWithCGSize:CGSizeMake(500, 688)],
[NSValue valueWithCGSize:CGSizeMake(377, 700)],
[NSValue valueWithCGSize:CGSizeMake(334, 494)],
[NSValue valueWithCGSize:CGSizeMake(625, 469)],
[NSValue valueWithCGSize:CGSizeMake(625, 833)],
[NSValue valueWithCGSize:CGSizeMake(625, 469)],
[NSValue valueWithCGSize:CGSizeMake(625, 469)],
[NSValue valueWithCGSize:CGSizeMake(625, 791)],
[NSValue valueWithCGSize:CGSizeMake(625, 833)],
[NSValue valueWithCGSize:CGSizeMake(605, 605)],
[NSValue valueWithCGSize:CGSizeMake(504, 750)],
[NSValue valueWithCGSize:CGSizeMake(500, 500)],
[NSValue valueWithCGSize:CGSizeMake(640, 640)],
[NSValue valueWithCGSize:CGSizeMake(500, 473)],
];
dispatch_group_t group = dispatch_group_create();
CGRect bounds = self.collectionView.bounds;
NSMutableArray *tmpKittens = [[NSMutableArray alloc] init];
CGFloat scale = [[UIScreen mainScreen] scale];
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSInteger count = 0;
for (NSInteger idx = 0; idx < 500; idx++) {
Kitten *kitten = [[Kitten alloc] init];
CGFloat r = (rand() % 255) / 255.0f;
CGFloat g = (rand() % 255) / 255.0f;
CGFloat b = (rand() % 255) / 255.0f;
kitten.dominantColor = [UIColor colorWithRed:r green:g blue:b alpha:1.0f];
NSUInteger kittenIdx = rand() % 20;
CGSize size = [kittenSizes[kittenIdx] CGSizeValue];
NSInteger width = size.width;
NSInteger height = size.height;
if (width > (bounds.size.width * scale)) {
height = ((bounds.size.width * scale) / width) * height;
width = (bounds.size.width * scale);
}
kitten.imageURL = kittenURLs[kittenIdx];
kitten.imageSize = CGSizeMake(width / scale, height / scale);
dispatch_sync(dispatch_get_main_queue(), ^{
[tmpKittens addObject:kitten];
});
count++;
}
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
[self.kittens addObjectsFromArray:tmpKittens];
[Kitten fetchKittenForWidth:CGRectGetWidth(self.collectionView.frame) completion:^(NSArray *kittens) {
[self.kittens addObjectsFromArray:kittens];
[self.collectionView reloadData];
});
}];
}
- (void)viewDidLoad
@@ -143,7 +60,7 @@
[self.view addSubview:self.collectionView];
self.kittens = [[NSMutableArray alloc] init];
[self addImages];
[self fetchKittenImages];
}
- (CGSize)collectionView:(UICollectionView *)collectionView
@@ -185,12 +102,6 @@
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@implementation PINImageCell
@@ -213,7 +124,3 @@
}
@end
@implementation Kitten
@end