Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Fix thumbnail generation bug for retina display

* Added support for iOS 5.0.1
  • Loading branch information...
commit 35ff613f188d9da8478cfce33b2c7fc7f87de1f7 1 parent 66f09ed
@bilalmughal authored
View
29 ImageShowcase.xcodeproj/project.pbxproj
@@ -86,6 +86,7 @@
9C4E36D3167E3BBF005D3B4C /* 5.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 5.png; sourceTree = "<group>"; };
9C4E36D4167E3BBF005D3B4C /* 6.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 6.png; sourceTree = "<group>"; };
9C4E36E3167E469A005D3B4C /* License.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = License.txt; sourceTree = "<group>"; };
+ 9CCB6BA9168A3E3B00B3D6BF /* Utility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Utility.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -151,6 +152,7 @@
9C1E97DA165AD3E100394F15 /* NLImageShowcaseCellDelegate.h */,
9C4E36A3167DFE0E005D3B4C /* NLImageViewer.h */,
9C4E36A4167DFE0E005D3B4C /* NLImageViewer.m */,
+ 9CCB6BA9168A3E3B00B3D6BF /* Utility.h */,
);
path = ImageShowcase;
sourceTree = "<group>";
@@ -212,6 +214,7 @@
9C360FFB1658FB5C00D03E64 /* Sources */,
9C360FFC1658FB5C00D03E64 /* Frameworks */,
9C360FFD1658FB5C00D03E64 /* Resources */,
+ 9CD7F838168A384D003A285D /* ShellScript */,
);
buildRules = (
);
@@ -282,6 +285,22 @@
};
/* End PBXResourcesBuildPhase section */
+/* Begin PBXShellScriptBuildPhase section */
+ 9CD7F838168A384D003A285D /* ShellScript */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "";
+ };
+/* End PBXShellScriptBuildPhase section */
+
/* Begin PBXSourcesBuildPhase section */
9C360FFB1658FB5C00D03E64 /* Sources */ = {
isa = PBXSourcesBuildPhase;
@@ -380,10 +399,15 @@
9C3610271658FB5D00D03E64 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CODE_SIGN_IDENTITY = JailbrokeDeveloper;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = JailbrokeDeveloper;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ImageShowcase/ImageShowcase-Prefix.pch";
INFOPLIST_FILE = "ImageShowcase/ImageShowcase-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
+ PROVISIONING_PROFILE = "";
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
WRAPPER_EXTENSION = app;
};
name = Debug;
@@ -391,10 +415,15 @@
9C3610281658FB5D00D03E64 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CODE_SIGN_IDENTITY = JailbrokeDeveloper;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = JailbrokeDeveloper;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ImageShowcase/ImageShowcase-Prefix.pch";
INFOPLIST_FILE = "ImageShowcase/ImageShowcase-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
+ PROVISIONING_PROFILE = "";
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
WRAPPER_EXTENSION = app;
};
name = Release;
View
2  ImageShowcase/NLImageShowCase.h
@@ -30,7 +30,7 @@
#import "NLImageViewDataSource.h"
#import "NLImageShowcaseCellDelegate.h"
-@interface NLImageShowCase : UIView <NLImageShowcaseCellDelegate>
+@interface NLImageShowCase : UIView <NLImageShowcaseCellDelegate,UIGestureRecognizerDelegate>
{
@private
UIScrollView* _scrollView;
View
10 ImageShowcase/NLImageShowCase.m
@@ -56,12 +56,19 @@ - (id)initWithFrame:(CGRect)frame
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewClicked)];
+ tap.delegate = self;
[self addGestureRecognizer:tap];
-
return self;
}
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
+ if ([touch.view isKindOfClass:[UIButton class]]) {
+ // Ignore touch: As we do not want to handle gesture here, so pass it to NLImageShowCaseCell
+ return NO;
+ }
+ return YES;
+}
- (id)setDataSource:(id<NLImageViewDataSource>)dataSource
{
@@ -149,7 +156,6 @@ -(void) setDeleteMode:(BOOL)deleteMode
- (void) viewClicked
{
- NSLog(@"Image Case clicked");
if (_deleteMode) {
[self setDeleteMode:false];
}
View
5 ImageShowcase/NLImageShowCaseCell.h
@@ -43,5 +43,10 @@
@property (nonatomic, readwrite) BOOL deleteMode;
- (id)initWithImage:(UIImage*)image;
- (id)setMainImage:(UIImage*)image;
+- (IBAction)buttonClicked;
+- (IBAction) deleteImage;
+- (IBAction)touchCancel;
+- (IBAction)touchDown;
+- (IBAction)imagePushedLonger;
@end
View
39 ImageShowcase/NLImageShowCaseCell.m
@@ -25,6 +25,7 @@
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "NLImageShowCaseCell.h"
+#import "Utility.h"
#import <QuartzCore/QuartzCore.h>
@implementation NLImageShowCaseCell
@@ -37,7 +38,7 @@ - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
- CGFloat delButtonSize = 40;
+ CGFloat delButtonSize = 60;
_deleteMode = NO;
_deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, delButtonSize, delButtonSize)];
@@ -58,11 +59,14 @@ - (id)initWithFrame:(CGRect)frame
_mainImage.imageView.layer.shadowOpacity = 0.6;
_mainImage.imageView.layer.shadowRadius = 1.0;
_mainImage.imageView.clipsToBounds = NO;
+ _mainImage.userInteractionEnabled = YES;
- [_mainImage addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
+ [_mainImage addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
+
[_deleteButton addTarget:self action:@selector(deleteImage) forControlEvents:UIControlEventTouchUpInside];
- [_mainImage addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
- [_mainImage addTarget:self action:@selector(touchCancel:) forControlEvents:UIControlEventTouchUpOutside];
+ [_mainImage addTarget:self action:@selector(touchDown) forControlEvents:UIControlEventTouchDown];
+ [_mainImage addTarget:self action:@selector(touchCancel) forControlEvents:UIControlEventTouchUpOutside];
+
return self;
}
@@ -84,13 +88,13 @@ -(void) setDeleteMode:(BOOL)deleteMode
[anim setAutoreverses:YES];
self.layer.shouldRasterize = YES;
[self.layer addAnimation:anim forKey:@"SpringboardShake"];
- _mainImage.userInteractionEnabled = NO;
+ //_mainImage.userInteractionEnabled = NO;
_deleteButton.hidden = NO;
}
else
{
[self.layer removeAllAnimations];
- _mainImage.userInteractionEnabled = YES;
+ //_mainImage.userInteractionEnabled = YES;
_deleteButton.hidden = YES;
}
}
@@ -98,7 +102,7 @@ -(void) setDeleteMode:(BOOL)deleteMode
- (void)resetView
{
[self.layer removeAllAnimations];
- self.userInteractionEnabled = YES;
+// self.userInteractionEnabled = YES;
[self setDeleteMode:NO];
}
@@ -113,15 +117,16 @@ - (UIImage*)getThumbnail:(UIImage*) image
float imgWidth = image.size.width;
float imgHeight = image.size.height;
- float width = self.bounds.size.width;
- float height = self.bounds.size.height;
+ float width = self.bounds.size.width*(isRetina ? 2.0f : 1.0f);
+ float height = self.bounds.size.height*(isRetina ? 2.0f : 1.0f);
float horz = imgWidth / width;
float vert = imgHeight / height;
+
float x1 = 0,x2 = 0,y1 = 0,y2 = 0;
- float scalingFactor = vert < horz ? vert : horz;
+ float scalingFactor = vert < horz ? vert * (isRetina ? 2.0f : 1.0f) : horz * (isRetina ? 2.0f : 1.0f);
UIImage* resizedImage = [self resizeImage:image resizeSize:CGSizeMake(imgWidth/scalingFactor, imgHeight/scalingFactor)];
@@ -157,7 +162,6 @@ - (UIImage*)getThumbnail:(UIImage*) image
}
- (UIImage *)resizeImage:(UIImage*)image resizeSize:(CGSize)resizeSize {
-
CGImageRef refImage = image.CGImage;
CGRect resizedRect = CGRectIntegral(CGRectMake(0, 0, resizeSize.width, resizeSize.height));
UIGraphicsBeginImageContextWithOptions(resizeSize, NO, 0);
@@ -175,28 +179,31 @@ - (UIImage *)resizeImage:(UIImage*)image resizeSize:(CGSize)resizeSize {
}
-- (void)buttonClicked:(id)sender {
+- (IBAction)buttonClicked {
if(_deleteMode)
return;
[_timer invalidate];
[_cellDelegate imageClicked:self imageIndex:_index];
}
-- (void) deleteImage {
+- (IBAction) deleteImage {
[_cellDelegate deleteImage:self imageIndex:_index];
+ [_timer invalidate];
}
-- (void)touchCancel:(id)sender {
+- (IBAction)touchCancel {
[_timer invalidate];
}
-- (void)touchDown:(id)sender {
+- (IBAction)touchDown {
+ if(_deleteMode)
+ return;
_timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(imagePushedLonger)
userInfo:nil
repeats:YES];
}
-- (void)imagePushedLonger
+- (IBAction)imagePushedLonger
{
[_timer invalidate];
[_cellDelegate imageTouchLonger:self imageIndex:_index];
View
2  ImageShowcase/NLViewController.h
@@ -37,6 +37,6 @@
}
- (IBAction)addImages:(id)sender;
-
+-(NSUInteger)supportedInterfaceOrientations;
@end
View
44 ImageShowcase/NLViewController.m
@@ -45,15 +45,11 @@ - (void)viewDidLoad
_imageShowCase.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tile.png"]];
_imageViewer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tile.png"]];
_imagViewController = [[UIViewController alloc] init];
- UIView* navView = _imagViewController.view;
- [navView addSubview:_imageViewer];
+ [_imagViewController.view addSubview:_imageViewer];
-
-
[self.view addSubview:_imageShowCase];
[self.view setAutoresizesSubviews:YES];
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
-
}
- (void)didReceiveMemoryWarning
@@ -61,9 +57,20 @@ - (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
}
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
+{
+ return YES;
+}
+
+-(NSUInteger)supportedInterfaceOrientations
+{
+ return UIInterfaceOrientationMaskAll;
+}
+
- (IBAction)addImages:(id)sender
{
static int counter=0;
+ [_imageShowCase setDeleteMode:NO];
NSString* imageName = [NSString stringWithFormat:@"%d.jpg",++counter];
[_imageShowCase addImage:[UIImage imageNamed:imageName]];
counter = counter % 6;
@@ -72,13 +79,13 @@ - (IBAction)addImages:(id)sender
#pragma mark - Image Showcase Protocol
- (CGSize)imageViewSizeInShowcase:(NLImageShowCase *) imageShowCase
{
-// return CGSizeMake(120, 80);
- return CGSizeMake(55, 70);
+ return CGSizeMake(120, 80);
+// return CGSizeMake(55, 70);
}
- (CGFloat)imageLeftOffsetInShowcase:(NLImageShowCase *) imageShowCase
{
-// return 25.0f;
- return 20.0f;
+ return 25.0f;
+// return 20.0f;
}
- (CGFloat)imageTopOffsetInShowcase:(NLImageShowCase *) imageShowCase
{
@@ -86,32 +93,23 @@ - (CGFloat)imageTopOffsetInShowcase:(NLImageShowCase *) imageShowCase
}
- (CGFloat)rowSpacingInShowcase:(NLImageShowCase *) imageShowCase
{
- return 20.0f;
-// return 25.0f;
+// return 20.0f;
+ return 25.0f;
}
- (CGFloat)columnSpacingInShowcase:(NLImageShowCase *) imageShowCase
{
- return 20.0f;
-// return 25.0f;
+// return 20.0f;
+ return 25.0f;
}
- (void)imageClicked:(NLImageShowCase *) imageShowCase imageShowCaseCell:(NLImageShowCaseCell *)imageShowCaseCell;
{
-
-// UIImage* image = [imageShowCaseCell image];
-
-// imagViewController.title = @"Hello";
[_imageViewer setImage:[imageShowCaseCell image]];
[self.navigationController pushViewController:_imagViewController animated:YES];
-// [self.navigationController pushViewController:tempView animated:YES];
-
-// NSLog(@"NLViewController: Image Clicked: %d",index);
-
}
- (void)imageTouchLonger:(NLImageShowCase *)imageShowCase imageIndex:(NSInteger)index;
{
- NSLog(@"NLViewController: imageTouchLonger: %d",index);
- [_imageShowCase setDeleteMode:!(_imageShowCase.deleteMode)];
+ [_imageShowCase setDeleteMode:!(_imageShowCase.deleteMode)];
}
@end
View
14 ImageShowcase/Utility.h
@@ -0,0 +1,14 @@
+//
+// Utility.h
+// ImageShowcase
+//
+// Created by Mirza Bilal on 12/26/12.
+// Copyright (c) 2012 Mirza Bilal. All rights reserved.
+//
+
+#ifndef ImageShowcase_Utility_h
+#define ImageShowcase_Utility_h
+
+#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.