Skip to content

Commit

Permalink
Bug fix, shadow rendering now compatible with iOS <3.2, tested on iOS…
Browse files Browse the repository at this point in the history
… 3.1.3 (fixes #2)
  • Loading branch information
Scott White committed Mar 8, 2012
1 parent f74241e commit 3de1b16
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ I use Snapshot Stack View to display a thumbnail to the user within an article f
Compatability
-------------

Snapshot Stack View has been developed to run on iOS 3.2 or later (Deployment Target) and was developed using iOS SDK 5.0, Xcode 4.2.1 (Base SDK).
Snapshot Stack View has been developed to run on iOS 3.1 or later (Deployment Target) and was developed using iOS SDK 5.0, Xcode 4.2.1 (Base SDK).

Support for iOS 3 was required for the target application I initially developed Snapshot Stack View for and hence Snapshot Stack View does NOT make use of any of the newer iOS features such as blocks or more importantly Automatic Reference Counting (ARC).

Expand Down
13 changes: 10 additions & 3 deletions SWSnapshotStackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
** Open Source Initiative OSI - The MIT License,
** see <http://www.opensource.org/licenses/MIT/>.
** MIT License, see <http://www.opensource.org/licenses/MIT/>.
**
** \see SNWSnapshotStackView.m
*/
Expand All @@ -39,7 +38,7 @@
//
// Project : iOS Common Components
// Component : GUI/Views
// Platform : iOS SDK 3.0+
// Platform : iOS SDK 3.1+
//
////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -120,6 +119,14 @@ SnapshotPosition_t;
//! Minimum scaling factor was calculated using image width (YES) otherwise
//! height (NO), stored to avoid recalculation and comparison when drawing.
BOOL m_scaledUsingWidth;

//! Shadow Direction Sign
//! Support for inversion of shadow base translation, y-axis in iOS 3.2+
//! Stored to avoid having to recheck system OS version during redrawing etc.
//! In <3.2, positive y, translates shadow DOWN
//! In 3.2+, positive y, translates shadow UP
//! NOTE: Not required if you do not wish to support iOS <3.2
CGFloat m_shadowDirSign;
}


Expand Down
16 changes: 12 additions & 4 deletions SWSnapshotStackView.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//
// Project : iOS Common Components
// Component : GUI/Views
// Platform : iOS SDK 3.0+
// Platform : iOS SDK 3.1+
//
////////////////////////////////////////////////////////////////////////////

Expand All @@ -49,7 +49,7 @@
// SNAPSHOT STACK VIEW CLASS (PRIVATE METHODS)
// ********************************************************************** //

#pragma mark Snapshot Stack View class (Private Methods)
#pragma mark Snapshot Stack View class (Private Interface)

@interface SWSnapshotStackView (Private)

Expand Down Expand Up @@ -221,6 +221,14 @@ - (void)commonInitialisation

// View's background is transparent underneath the rendered snapshot(s)
self.backgroundColor = [UIColor clearColor];

// Check system (iOS) version, invert sign of shadow direction when
// running on iOS <3.2
m_shadowDirSign = 1.0;
if (NSOrderedAscending == [[[UIDevice currentDevice] systemVersion] compare:@"3.2" options:NSNumericSearch])
{
m_shadowDirSign = -1.0;
}
}


Expand Down Expand Up @@ -314,7 +322,7 @@ - (void)drawRect:(CGRect)rect

// Draw the shadow using it's calculated path
colour = [UIColor colorWithRed:0 green:0 blue:0.0 alpha:0.6];
CGContextSetShadowWithColor (context, CGSizeMake (0, SWSnapshotStackViewSingleShadowYOffset),
CGContextSetShadowWithColor (context, CGSizeMake (0, (SWSnapshotStackViewSingleShadowYOffset * m_shadowDirSign)),
SWSnapshotStackViewSingleShadowRadius, colour.CGColor);
CGContextAddPath (context, shadowPath);
CGContextFillPath (context);
Expand Down Expand Up @@ -432,7 +440,7 @@ - (void)drawRect:(CGRect)rect
// slightly. Still not 100% happy with the shadow drawing, plan
// to tweak eventually to get better end effect
colour = [UIColor colorWithRed:0 green:0 blue:0.0 alpha:0.4];
CGContextSetShadowWithColor (context, CGSizeMake (0.0, SWSnapshotStackViewStackShadowYOffset),
CGContextSetShadowWithColor (context, CGSizeMake (0.0, (SWSnapshotStackViewStackShadowYOffset * m_shadowDirSign)),
SWSnapshotStackViewStackShadowRadius, colour.CGColor);
CGContextAddPath (context, matteFramePath);
CGContextFillPath (context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = (
armv6,
"$(ARCHS_STANDARD_32_BIT)",
);
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -246,7 +249,7 @@
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
IPHONEOS_DEPLOYMENT_TARGET = 3.1;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -255,15 +258,18 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = (
armv6,
"$(ARCHS_STANDARD_32_BIT)",
);
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
IPHONEOS_DEPLOYMENT_TARGET = 3.1;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -276,8 +282,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SWSnapshotStackViewDemo/SWSnapshotStackViewDemo-Prefix.pch";
INFOPLIST_FILE = "SWSnapshotStackViewDemo/SWSnapshotStackViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
IPHONEOS_DEPLOYMENT_TARGET = 3.1;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -288,8 +295,9 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SWSnapshotStackViewDemo/SWSnapshotStackViewDemo-Prefix.pch";
INFOPLIST_FILE = "SWSnapshotStackViewDemo/SWSnapshotStackViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
IPHONEOS_DEPLOYMENT_TARGET = 3.1;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down

0 comments on commit 3de1b16

Please sign in to comment.