Skip to content

Commit

Permalink
Merge pull request #10 from bryceredd/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
bryceredd committed Aug 29, 2013
2 parents 8bbae74 + d87c94f commit a0bc578
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 493 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>1979D376-5357-476C-8EAB-7832139AF792</string>
<key>IDESourceControlProjectName</key>
<string>QuiltDemo</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>06AE9A8A-F38E-41A9-879C-38ABFFD8E44D</key>
<string>ssh://github.com/bryceredd/RFQuiltLayout.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>QuiltDemo.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>06AE9A8A-F38E-41A9-879C-38ABFFD8E44D</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/bryceredd/RFQuiltLayout.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>06AE9A8A-F38E-41A9-879C-38ABFFD8E44D</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>06AE9A8A-F38E-41A9-879C-38ABFFD8E44D</string>
<key>IDESourceControlWCCName</key>
<string>RFQuiltLayout</string>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
<Bucket
type = "1"
version = "1.0">
<FileBreakpoints>
<FileBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "RFQuiltLayout/RFQuiltLayout.m"
timestampString = "398271859.052302"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "140"
endingLineNumber = "140"
landmarkName = "-prepareLayout"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "RFQuiltLayout/RFQuiltLayout.m"
timestampString = "398271860.651295"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "130"
endingLineNumber = "130"
landmarkName = "-invalidateLayout"
landmarkType = "5">
</FileBreakpoint>
</FileBreakpoints>
<ExceptionBreakpoints>
<ExceptionBreakpoint
shouldBeEnabled = "Yes"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
29 changes: 23 additions & 6 deletions QuiltDemo/RFViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#import "RFViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface RFViewController ()
@interface RFViewController () {
BOOL isAnimating;
}
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic) NSMutableArray* numbers;
@end
Expand All @@ -21,7 +23,7 @@ @implementation RFViewController
- (void)viewDidLoad {

self.numbers = [@[] mutableCopy];
for(; num<50; num++) { [self.numbers addObject:@(num)]; }
for(; num<100; num++) { [self.numbers addObject:@(num)]; }

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];

Expand All @@ -39,19 +41,33 @@ - (void) viewDidAppear:(BOOL)animated {
- (IBAction)remove:(id)sender {
if(!self.numbers.count) return;

if(isAnimating) return;
isAnimating = YES;

[self.collectionView performBatchUpdates:^{
int index = arc4random() % MAX(1, self.numbers.count);
[self.numbers removeObjectAtIndex:index];
[self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]]];
} completion:nil];
} completion:^(BOOL done) {
isAnimating = NO;
}];
}

- (IBAction)refresh:(id)sender {
[self.collectionView reloadData];
}

- (IBAction)add:(id)sender {
if(isAnimating) return;
isAnimating = YES;

[self.collectionView performBatchUpdates:^{
int index = arc4random() % self.numbers.count;
int index = arc4random() % MAX(self.numbers.count,1);
[self.numbers insertObject:@(++num) atIndex:index];
[self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]]];
} completion:nil];
} completion:^(BOOL done) {
isAnimating = NO;
}];
}

- (UIColor*) colorForNumber:(NSNumber*)num {
Expand All @@ -69,7 +85,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtInd
cell.backgroundColor = [self colorForNumber:self.numbers[indexPath.row]];

UILabel* label = (id)[cell viewWithTag:5];
if(!label) label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 20, 20)];
if(!label) label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 30, 20)];
label.tag = 5;
label.textColor = [UIColor blackColor];
label.text = [NSString stringWithFormat:@"%@", self.numbers[indexPath.row]];
Expand All @@ -83,6 +99,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtInd
#pragma mark – RFQuiltLayoutDelegate

- (CGSize) blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath {

if(indexPath.row >= self.numbers.count)
NSLog(@"Asking for index paths of non-existant cells!! %d from %d cells", indexPath.row, self.numbers.count);

Expand Down

0 comments on commit a0bc578

Please sign in to comment.