Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Documented NSData category. Documented UIView category. Added UIView …

…category test. Removed old, messy UIView categories. Use new block API for UIView category animations. #24
  • Loading branch information...
commit 3a1e6cea9a1c45696d58a0a3d9e035ac15e5c4e4 1 parent 2ad922a
@soffes soffes authored
View
4 SSToolkit.xcodeproj/project.pbxproj
@@ -129,6 +129,7 @@
B2EA9F6212F4A5E100C929D6 /* SSBadgeView.h in Headers */ = {isa = PBXBuildFile; fileRef = B2EA9F6012F4A5E100C929D6 /* SSBadgeView.h */; };
B2EA9F6312F4A5E100C929D6 /* SSBadgeView.m in Sources */ = {isa = PBXBuildFile; fileRef = B2EA9F6112F4A5E100C929D6 /* SSBadgeView.m */; };
B2FC71BB1330424F00D4FCCF /* SSCollectionViewItemInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = B2FC71BA1330424F00D4FCCF /* SSCollectionViewItemInternal.h */; };
+ B2FC9F5213CA73AB001E3F17 /* ViewCategoryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B2FC9F5113CA73AB001E3F17 /* ViewCategoryTest.m */; };
B2FE26B9136684D400B97612 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FE26B8136684D400B97612 /* QuartzCore.framework */; };
/* End PBXBuildFile section */
@@ -269,6 +270,7 @@
B2EA9F6012F4A5E100C929D6 /* SSBadgeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSBadgeView.h; sourceTree = "<group>"; };
B2EA9F6112F4A5E100C929D6 /* SSBadgeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSBadgeView.m; sourceTree = "<group>"; };
B2FC71BA1330424F00D4FCCF /* SSCollectionViewItemInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSCollectionViewItemInternal.h; sourceTree = "<group>"; };
+ B2FC9F5113CA73AB001E3F17 /* ViewCategoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewCategoryTest.m; sourceTree = "<group>"; };
B2FE26B8136684D400B97612 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
D2AAC07E0554694100DB518D /* libSSToolkit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSSToolkit.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -359,6 +361,7 @@
B23910A71357DED300ADE21B /* DictionaryCategoryTest.m */,
B23910A81357DED300ADE21B /* StringCategoryTest.m */,
B23910C31357E08E00ADE21B /* URLCategoryTest.m */,
+ B2FC9F5113CA73AB001E3F17 /* ViewCategoryTest.m */,
B23910681357DD0B00ADE21B /* Frameworks */,
B23910801357DDA600ADE21B /* GHUnitIOSTestMain.m */,
B239105B1357DCA900ADE21B /* SSToolkitTests_Prefix.pch */,
@@ -721,6 +724,7 @@
B2453A1D1394AE5000275B6B /* DictionaryCategoryTest.m in Sources */,
B2453A1E1394AE5000275B6B /* StringCategoryTest.m in Sources */,
B2453A1F1394AE5000275B6B /* URLCategoryTest.m in Sources */,
+ B2FC9F5213CA73AB001E3F17 /* ViewCategoryTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
13 SSToolkit/NSData+SSToolkitAdditions.h
@@ -22,7 +22,20 @@
/// @name Base64 Encoding and Decoding
///-----------------------------------
+/**
+ Returns a string representation of the receiver Base64 encoded.
+
+ @return A Base64 encoded string
+ */
- (NSString *)base64EncodedString;
+
+/**
+ Returns a new data contained in the Base64 encoded string.
+
+ @param base64String A Base64 encoded string
+
+ @return Data contained in `base64String`
+ */
+ (NSData *)dataWithBase64String:(NSString *)base64String;
@end
View
54 SSToolkit/UIView+SSToolkitAdditions.h
@@ -15,36 +15,74 @@
/// @name Taking Screenshots
///-------------------------
+/**
+ Takes a screenshot of the underlying `CALayer` of the receiver and returns a `UIImage` object representation.
+
+ @return An image representing the receiver
+ */
- (UIImage *)imageRepresentation;
///-------------------------
/// @name Hiding and Showing
///-------------------------
+/**
+ Sets the `alpha` value of the receiver to `0.0`.
+ */
- (void)hide;
+
+/**
+ Sets the `alpha` value of the receiver to `1.0`.
+ */
- (void)show;
///------------------------
/// @name Fading In and Out
///------------------------
+/**
+ Fade out the receiver.
+
+ The receiver will fade out in `0.2` seconds.
+ */
- (void)fadeOut;
-- (void)fadeOutAndPerformSelector:(SEL)selector;
-- (void)fadeOutAndPerformSelector:(SEL)selector withObject:(id)object;
-- (void)fadeIn;
-- (void)fadeInAndPerformSelector:(SEL)selector;
-- (void)fadeInAndPerformSelector:(SEL)selector withObject:(id)object;
+/**
+ Fade out the receiver and remove from its super view
+
+ The receiver will fade out in `0.2` seconds and be removed from its `superview` when the animation completes.
+ */
+- (void)fadeOutAndRemoveFromSuperview;
-- (void)fadeAlphaTo:(CGFloat)targetAlpha;
-- (void)fadeAlphaTo:(CGFloat)targetAlpha andPerformSelector:(SEL)selector;
-- (void)fadeAlphaTo:(CGFloat)targetAlpha andPerformSelector:(SEL)selector withObject:(id)object;
+/**
+ Fade in the receiver.
+
+ The receiver will fade in in `0.2` seconds.
+ */
+- (void)fadeIn;
///----------------------------------
/// @name Managing the View Hierarchy
///----------------------------------
+/**
+ Returns an array of the receiver's superviews.
+
+ The immediate super view is the first object in the array. The outer most super view is the last object in the array.
+
+ @return An array of view objects containing the receiver
+ */
- (NSArray *)superviews;
+
+/**
+ Returns the first super view of a given class.
+
+ If a super view is not found for the given `superviewClass`, `nil` is returned.
+
+ @param superviewClass A Class to search the `superviews` for
+
+ @return A view object or `nil`
+ */
- (id)firstSuperviewOfClass:(Class)superviewClass;
@end
View
69 SSToolkit/UIView+SSToolkitAdditions.m
@@ -31,60 +31,31 @@ - (void)show {
- (void)fadeOut {
- [self fadeAlphaTo:0.0f andPerformSelector:NULL withObject:nil];
+ UIView *view = [self retain];
+ [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
+ view.alpha = 0.0f;
+ } completion:nil];
+ [view autorelease];
}
-- (void)fadeOutAndPerformSelector:(SEL)selector {
- [self fadeAlphaTo:0.0f andPerformSelector:selector withObject:nil];
-}
-
-
-- (void)fadeOutAndPerformSelector:(SEL)selector withObject:(id)object {
- [self fadeAlphaTo:0.0f andPerformSelector:selector withObject:object];
+- (void)fadeOutAndRemoveFromSuperview {
+ UIView *view = [self retain];
+ [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
+ view.alpha = 0.0f;
+ } completion:^(BOOL finished) {
+ [view removeFromSuperview];
+ }];
+ [view autorelease];
}
- (void)fadeIn {
- [self fadeAlphaTo:1.0f andPerformSelector:NULL withObject:nil];
-}
-
-
-- (void)fadeInAndPerformSelector:(SEL)selector {
- [self fadeAlphaTo:1.0f andPerformSelector:selector withObject:nil];
-}
-
-
-- (void)fadeInAndPerformSelector:(SEL)selector withObject:(id)object {
- [self fadeAlphaTo:1.0f andPerformSelector:selector withObject:object];
-}
-
-
-- (void)fadeAlphaTo:(CGFloat)targetAlpha {
- [self fadeAlphaTo:targetAlpha andPerformSelector:NULL withObject:nil];
-}
-
-
-- (void)fadeAlphaTo:(CGFloat)targetAlpha andPerformSelector:(SEL)selector {
- [self fadeAlphaTo:targetAlpha andPerformSelector:selector withObject:nil];
-}
-
-
-- (void)fadeAlphaTo:(CGFloat)targetAlpha andPerformSelector:(SEL)selector withObject:(id)object {
- // Don't fade and perform selector if alpha is already target alpha
- if (self.alpha == targetAlpha) {
- return;
- }
-
- // Perform fade
- [UIView beginAnimations:@"fadealpha" context:nil];
- self.alpha = targetAlpha;
- [UIView commitAnimations];
-
- // Perform selector after animation
- if (selector) {
- [self performSelector:selector withObject:object afterDelay:0.21];
- }
+ UIView *view = [self retain];
+ [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
+ view.alpha = 1.0f;
+ } completion:nil];
+ [view autorelease];
}
@@ -95,6 +66,10 @@ - (NSArray *)superviews {
UIView *superview = nil;
while (view) {
superview = [view superview];
+ if (!superview) {
+ break;
+ }
+
[superviews addObject:superview];
view = superview;
}
View
80 Tests/ViewCategoryTest.m
@@ -0,0 +1,80 @@
+//
+// ViewTest.m
+// SSToolkit
+//
+// Created by Sam Soffes on 7/10/11.
+// Copyright 2011 Sam Soffes. All rights reserved.
+//
+
+#import <SSToolkit/UIView+SSToolkitAdditions.h>
+#import <SSToolkit/SSLineView.h>
+
+@interface ViewCategoryTest : GHTestCase
+@end
+
+@implementation ViewCategoryTest
+
+- (void)testHide {
+ UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
+ [view hide];
+ GHAssertEquals(view.alpha, 0.0f, nil);
+ [view release];
+}
+
+
+- (void)testShow {
+ UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
+ view.alpha = 0.0f;
+ [view show];
+ GHAssertEquals(view.alpha, 1.0f, nil);
+ [view release];
+}
+
+
+- (void)testSuperviews {
+ UIView *one = [[UIView alloc] initWithFrame:CGRectZero];
+ UIView *two = [[UIView alloc] initWithFrame:CGRectZero];
+ UIView *three = [[UIView alloc] initWithFrame:CGRectZero];
+ UIView *four = [[UIView alloc] initWithFrame:CGRectZero];
+ UIView *five = [[UIView alloc] initWithFrame:CGRectZero];
+
+ [four addSubview:five];
+ [three addSubview:four];
+ [two addSubview:three];
+ [one addSubview:two];
+
+ NSArray *superviews = [[NSArray alloc] initWithObjects:four, three, two, one, nil];
+
+ GHAssertEqualObjects([five superviews], superviews, nil);
+
+ [superviews release];
+ [one release];
+ [two release];
+ [three release];
+ [four release];
+ [five release];
+}
+
+
+- (void)testFirstSuperviewOfClass {
+ UIView *one = [[SSLineView alloc] initWithFrame:CGRectZero];
+ UIView *two = [[SSLineView alloc] initWithFrame:CGRectZero];
+ UIView *three = [[UIView alloc] initWithFrame:CGRectZero];
+ UIView *four = [[UIView alloc] initWithFrame:CGRectZero];
+ UIView *five = [[UIView alloc] initWithFrame:CGRectZero];
+
+ [four addSubview:five];
+ [three addSubview:four];
+ [two addSubview:three];
+ [one addSubview:two];
+
+ GHAssertEqualObjects([five firstSuperviewOfClass:[SSLineView class]], two, nil);
+
+ [one release];
+ [two release];
+ [three release];
+ [four release];
+ [five release];
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.