diff --git a/QuiltDemo.xcodeproj/project.xcworkspace/xcshareddata/QuiltDemo.xccheckout b/QuiltDemo.xcodeproj/project.xcworkspace/xcshareddata/QuiltDemo.xccheckout
new file mode 100644
index 0000000..0b0c3b4
--- /dev/null
+++ b/QuiltDemo.xcodeproj/project.xcworkspace/xcshareddata/QuiltDemo.xccheckout
@@ -0,0 +1,41 @@
+
+
+
+
+ IDESourceControlProjectFavoriteDictionaryKey
+
+ IDESourceControlProjectIdentifier
+ 1979D376-5357-476C-8EAB-7832139AF792
+ IDESourceControlProjectName
+ QuiltDemo
+ IDESourceControlProjectOriginsDictionary
+
+ 06AE9A8A-F38E-41A9-879C-38ABFFD8E44D
+ ssh://github.com/bryceredd/RFQuiltLayout.git
+
+ IDESourceControlProjectPath
+ QuiltDemo.xcodeproj/project.xcworkspace
+ IDESourceControlProjectRelativeInstallPathDictionary
+
+ 06AE9A8A-F38E-41A9-879C-38ABFFD8E44D
+ ../..
+
+ IDESourceControlProjectURL
+ ssh://github.com/bryceredd/RFQuiltLayout.git
+ IDESourceControlProjectVersion
+ 110
+ IDESourceControlProjectWCCIdentifier
+ 06AE9A8A-F38E-41A9-879C-38ABFFD8E44D
+ IDESourceControlProjectWCConfigurations
+
+
+ IDESourceControlRepositoryExtensionIdentifierKey
+ public.vcs.git
+ IDESourceControlWCCIdentifierKey
+ 06AE9A8A-F38E-41A9-879C-38ABFFD8E44D
+ IDESourceControlWCCName
+ RFQuiltLayout
+
+
+
+
diff --git a/QuiltDemo.xcodeproj/project.xcworkspace/xcuserdata/bryce.xcuserdatad/UserInterfaceState.xcuserstate b/QuiltDemo.xcodeproj/project.xcworkspace/xcuserdata/bryce.xcuserdatad/UserInterfaceState.xcuserstate
index 46120e9..dc25d72 100644
Binary files a/QuiltDemo.xcodeproj/project.xcworkspace/xcuserdata/bryce.xcuserdatad/UserInterfaceState.xcuserstate and b/QuiltDemo.xcodeproj/project.xcworkspace/xcuserdata/bryce.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/QuiltDemo.xcodeproj/xcuserdata/bryce.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/QuiltDemo.xcodeproj/xcuserdata/bryce.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
index ac62168..36fdb11 100644
--- a/QuiltDemo.xcodeproj/xcuserdata/bryce.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
+++ b/QuiltDemo.xcodeproj/xcuserdata/bryce.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -2,6 +2,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/QuiltDemo/RFViewController.m b/QuiltDemo/RFViewController.m
index 66385bc..3cc5e2f 100644
--- a/QuiltDemo/RFViewController.m
+++ b/QuiltDemo/RFViewController.m
@@ -9,7 +9,9 @@
#import "RFViewController.h"
#import
-@interface RFViewController ()
+@interface RFViewController () {
+ BOOL isAnimating;
+}
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic) NSMutableArray* numbers;
@end
@@ -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"];
@@ -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 {
@@ -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]];
@@ -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);
diff --git a/QuiltDemo/en.lproj/RFViewController.xib b/QuiltDemo/en.lproj/RFViewController.xib
index e5ff70b..dfa43df 100644
--- a/QuiltDemo/en.lproj/RFViewController.xib
+++ b/QuiltDemo/en.lproj/RFViewController.xib
@@ -1,481 +1,81 @@
-
-
-
- 1536
- 12C3012
- 2844
- 1187.34
- 625.00
-
-
- IBNSLayoutConstraint
- IBProxyObject
- IBUIButton
- IBUICollectionView
- IBUICollectionViewLayout
- IBUIView
-
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
-
-
-
-
-
-
-
-
-
- view
-
-
-
- 7
-
-
-
- collectionView
-
-
-
- 14
-
-
-
- dataSource
-
-
-
- 15
-
-
-
- delegate
-
-
-
- 16
-
-
-
- delegate
-
-
-
- 19
-
-
-
- add:
-
-
- 7
-
- 30
-
-
-
- remove:
-
-
- 7
-
- 29
-
-
-
-
-
- 0
-
-
-
-
-
- -1
-
-
- File's Owner
-
-
- -2
-
-
-
-
- 6
-
-
-
-
- 3
- 0
-
- 3
- 1
-
- 20
-
- 1000
-
- 8
- 29
- 3
-
-
-
- 5
- 0
-
- 6
- 1
-
- 8
-
- 1000
-
- 6
- 24
- 3
-
-
-
- 5
- 0
-
- 5
- 1
-
- 20
-
- 1000
-
- 8
- 29
- 3
-
-
-
- 3
- 0
-
- 3
- 1
-
- 20
-
- 1000
-
- 8
- 29
- 3
-
-
-
- 5
- 0
-
- 5
- 1
-
- 0.0
-
- 1000
-
- 8
- 29
- 3
-
-
-
- 4
- 0
-
- 4
- 1
-
- 0.0
-
- 1000
-
- 8
- 29
- 3
-
-
-
- 6
- 0
-
- 6
- 1
-
- 0.0
-
- 1000
-
- 8
- 29
- 3
-
-
-
- 3
- 0
-
- 3
- 1
-
- 0.0
-
- 1000
-
- 8
- 29
- 3
-
-
-
-
-
-
-
-
- 8
-
-
-
-
-
-
-
- 10
-
-
-
-
- 11
-
-
-
-
- 12
-
-
-
-
- 13
-
-
-
-
- 18
-
-
-
-
- 20
-
-
-
-
- 21
-
-
-
-
- 22
-
-
-
-
- 23
-
-
-
-
- 26
-
-
-
-
- 28
-
-
-
-
-
-
- RFViewController
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- UIResponder
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- RFQuiltLayout
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
-
-
-
-
-
-
-
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
-
-
-
-
- 30
-
-
- 0
- IBCocoaTouchFramework
- YES
- 3
- YES
- 1930
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/RFQuiltLayout/RFQuiltLayout.m b/RFQuiltLayout/RFQuiltLayout.m
index cf88492..cb8f8cf 100644
--- a/RFQuiltLayout/RFQuiltLayout.m
+++ b/RFQuiltLayout/RFQuiltLayout.m
@@ -8,7 +8,6 @@
#import "RFQuiltLayout.h"
@interface RFQuiltLayout ()
-// todo put these back
@property(nonatomic) CGPoint firstOpenSpace;
@property(nonatomic) CGPoint furthestBlockPoint;
@@ -82,7 +81,7 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
int unrestrictedDimensionLength = (isVert? rect.size.height / self.blockPixels.height : rect.size.width / self.blockPixels.width) + 1;
int unrestrictedDimensionEnd = unrestrictedDimensionStart + unrestrictedDimensionLength;
- [self fillInBlocksToUnrestrictedRow:unrestrictedDimensionEnd];
+ [self fillInBlocksToUnrestrictedRow:self.prelayoutEverything? INT_MAX : unrestrictedDimensionEnd];
// find the indexPaths between those rows
NSMutableSet* attributes = [NSMutableSet set];
@@ -139,13 +138,15 @@ - (void) prepareLayout {
BOOL isVert = self.direction == UICollectionViewScrollDirectionVertical;
+ CGRect scrollFrame = CGRectMake(self.collectionView.contentOffset.x, self.collectionView.contentOffset.y, self.collectionView.frame.size.width, self.collectionView.frame.size.height);
+
int unrestrictedRow = 0;
if (isVert)
- unrestrictedRow = (self.collectionView.frame.size.height / [self blockPixels].height)+1;
+ unrestrictedRow = (CGRectGetMaxY(scrollFrame) / [self blockPixels].height)+1;
else
- unrestrictedRow = (self.collectionView.frame.size.width / [self blockPixels].width)+1;
+ unrestrictedRow = (CGRectGetMaxX(scrollFrame) / [self blockPixels].width)+1;
- [self fillInBlocksToUnrestrictedRow:unrestrictedRow];
+ [self fillInBlocksToUnrestrictedRow:self.prelayoutEverything? INT_MAX : unrestrictedRow];
}
- (void) setDirection:(UICollectionViewScrollDirection)direction {
@@ -317,7 +318,6 @@ - (void) clearPositions {
self.positionByIndexPath = [NSMutableDictionary dictionary];
}
-
- (NSIndexPath*)indexPathForPosition:(CGPoint)point {
BOOL isVert = self.direction == UICollectionViewScrollDirectionVertical;