forked from brynbellomy/iOS-DragAndDrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSEDraggableLocation.m
542 lines (456 loc) · 24.2 KB
/
SEDraggableLocation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
//
// SEDraggableLocation.m
// SEDraggable
//
// Created by bryn austin bellomy <[email protected]> on 10/24/11.
// Copyright (c) 2012 robot bubble bath LLC. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "SEDraggableLocation.h"
#import "SEDraggable.h"
const NSInteger SEDraggableLocationPositionDetermineAutomatically = -1;
@interface SEDraggableLocation ()
@property (nonatomic, readwrite, strong) UIView *highlightView;
- (void) acceptDraggableObject:(SEDraggable *)draggable entryMethod:(SEDraggableLocationEntryMethod)entryMethod animated:(BOOL)animated;
- (void) refuseDraggableObject:(SEDraggable *)draggable entryMethod:(SEDraggableLocationEntryMethod)entryMethod animated:(BOOL)animated;
- (CGPoint) calculateCenterOfDraggableObject:(SEDraggable *)object inPosition:(NSInteger)position;
- (CGPoint) getAcceptableWindowCoordsForDraggableObject:(SEDraggable *)object inPosition:(NSInteger)position;
@end
@implementation SEDraggableLocation
@synthesize responsiveBounds = _responsiveBounds;
@synthesize objectGutterBounds = _objectGutterBounds;
@synthesize shouldAcceptDroppedObjects = _shouldAcceptDroppedObjects;
@synthesize shouldAcceptObjectsSnappingBack = _shouldAcceptObjectsSnappingBack;
@synthesize shouldKeepObjectsArranged = _shouldKeepObjectsArranged;
@synthesize shouldAnimateObjectAdjustments = _shouldAnimateObjectAdjustments;
@synthesize animationDuration = _animationDuration;
@synthesize animationDelay = _animationDelay;
@synthesize animationOptions = _animationOptions;
@synthesize delegate = _delegate;
@synthesize containedObjects = _containedObjects;
@synthesize objectWidth = _objectWidth;
@synthesize objectHeight = _objectHeight;
@synthesize marginLeft = _marginLeft;
@synthesize marginRight = _marginRight;
@synthesize marginTop = _marginTop;
@synthesize marginBottom = _marginBottom;
@synthesize marginBetweenX = _marginBetweenX;
@synthesize marginBetweenY = _marginBetweenY;
@synthesize randomArrangementOffsetMultiplier = _randomArrangementOffsetMultiplier;
@synthesize fillHorizontallyFirst = _fillHorizontallyFirst;
@synthesize allowRows = _allowRows;
@synthesize allowColumns = _allowColumns;
@synthesize shouldHighlightOnDragOver = _shouldHighlightOnDragOver;
@dynamic highlightColor;
@dynamic highlightOpacity;
@synthesize highlightView = _highlightView;
#pragma mark- Lifecycle
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self defaultAllOwnProperties];
}
return self;
}
- (void) defaultAllOwnProperties {
CGRect localFrame = self.frame;
localFrame.origin = CGPointZero;
self.objectGutterBounds = [[UIView alloc] initWithFrame:localFrame];
self.objectGutterBounds.contentMode = UIViewContentModeScaleToFill;
self.objectGutterBounds.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addSubview:self.objectGutterBounds];
self.responsiveBounds = [[UIView alloc] initWithFrame:localFrame];
self.responsiveBounds.contentMode = UIViewContentModeScaleToFill;
self.responsiveBounds.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addSubview:self.responsiveBounds];
self.highlightView = [[UIView alloc] initWithFrame:localFrame];
self.highlightView.contentMode = UIViewContentModeScaleToFill;
self.highlightView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
// self.highlightView.layer. alpha = 0.0f;
// self.highlightView.backgroundColor = self.highlightColor;
// self.highlightView.hidden = YES;
[self showHighlight:NO]; // hide highlight layer initially
self.shouldHighlightOnDragOver = YES;
self.highlightColor = [UIColor redColor].CGColor;
self.highlightOpacity = 0.3f;
[self addSubview:self.highlightView];
self.containedObjects = [[NSMutableArray alloc] init];
self.shouldAcceptDroppedObjects = YES;
self.shouldAcceptObjectsSnappingBack = YES;
self.shouldKeepObjectsArranged = YES;
self.shouldAnimateObjectAdjustments = YES;
self.animationDuration = 0.3f;
self.animationDelay = 0.0f;
self.animationOptions = 0; //UIViewAnimationOptionBeginFromCurrentState;
self.delegate = nil;
self.objectWidth = 0;
self.objectHeight = 0;
self.marginLeft = 0;
self.marginRight = 0;
self.marginTop = 0;
self.marginBottom = 0;
self.marginBetweenX = 0;
self.marginBetweenY = 0;
self.randomArrangementOffsetMultiplier = 0.0f;
self.fillHorizontallyFirst = YES;
self.allowRows = YES;
self.allowColumns = YES;
}
- (CGColorRef) highlightColor {
return self.highlightView.layer.backgroundColor;
}
- (void) setHighlightColor:(CGColorRef)highlightColor {
self.highlightView.layer.backgroundColor = highlightColor;
}
- (CGFloat) highlightOpacity {
return self.highlightView.layer.opacity;
}
- (void) setHighlightOpacity:(CGFloat)highlightOpacity {
self.highlightView.layer.opacity = highlightOpacity;
}
- (void) showHighlight:(BOOL)show {
self.highlightView.layer.hidden = !show;
}
- (void) addSubview:(UIView *)view {
[super addSubview:view];
[self sendSubviewToBack:self.highlightView];
}
#pragma mark- Permission to enter location
- (BOOL) draggableObject:(SEDraggable *)draggable wantsToEnterLocationWithEntryMethod:(SEDraggableLocationEntryMethod)entryMethod animated:(BOOL)animated {
if (self.shouldHighlightOnDragOver) {
[self showHighlight:NO];
}
BOOL allow = YES; // default to allow
switch (entryMethod) {
case SEDraggableLocationEntryMethodWasDropped:
allow = self.shouldAcceptDroppedObjects;
break;
case SEDraggableLocationEntryMethodWantsToSnapBack:
allow = self.shouldAcceptObjectsSnappingBack;
break;
case SEDraggableLocationEntryMethodWasAdded:
// always allow when the draggable is force-added
allow = YES;
break;
default:
break;
}
if (allow) [self acceptDraggableObject:draggable entryMethod:entryMethod animated:animated];
else [self refuseDraggableObject:draggable entryMethod:entryMethod animated:animated];
return allow;
}
#pragma mark -- Convenience methods
- (BOOL) draggableObjectWantsToSnapBack:(SEDraggable *)draggable animated:(BOOL)animated {
return [self draggableObject:draggable wantsToEnterLocationWithEntryMethod:SEDraggableLocationEntryMethodWantsToSnapBack animated:animated];
}
- (BOOL) draggableObjectWasDroppedInside:(SEDraggable *)draggable animated:(BOOL)animated {
return [self draggableObject:draggable wantsToEnterLocationWithEntryMethod:SEDraggableLocationEntryMethodWasDropped animated:animated];
}
- (void) addDraggableObject:(SEDraggable *)draggable animated:(BOOL)animated {
[self draggableObject:draggable wantsToEnterLocationWithEntryMethod:SEDraggableLocationEntryMethodWasAdded animated:animated];
}
#pragma mark- Movement event handlers
- (void) draggableObjectDidMoveWithinBounds:(SEDraggable *)draggable {
if (self.shouldHighlightOnDragOver) {
[self showHighlight:YES];
}
}
- (void) draggableObjectDidMoveOutsideBounds:(SEDraggable *)draggable {
if (self.shouldHighlightOnDragOver) {
[self showHighlight:NO];
}
}
#pragma mark- Geometry helpers
- (CGPoint) calculateCenterOfDraggableObject:(SEDraggable *)object inPosition:(NSInteger)position {
CGPoint point;
CGRect rect = self.objectGutterBounds.frame;
int objectsPerRow = floor(((rect.size.width - self.marginLeft - self.marginRight - (2 * self.marginBetweenX)) / self.objectWidth));
int objectsPerCol = floor(((rect.size.height - self.marginTop - self.marginBottom - (2 * self.marginBetweenY)) / self.objectHeight));
int row, col;
// prevent divide-by-zero errors
if (objectsPerRow == 0) objectsPerRow = 1;
if (objectsPerCol == 0) objectsPerCol = 1;
if (self.fillHorizontallyFirst) {
col = position % objectsPerRow;
row = (position - col) / objectsPerRow;
}
else {
row = position % objectsPerCol;
col = (position - row) / objectsPerCol;
}
point.x = rect.origin.x + self.marginLeft + (col * (self.marginBetweenX + self.objectWidth)) + (self.objectWidth / 2);
point.y = rect.origin.y + self.marginTop + (row * (self.marginBetweenY + self.objectHeight)) + (self.objectHeight / 2);
return point;
}
- (CGPoint) getAcceptableWindowCoordsForDraggableObject:(SEDraggable *)object inPosition:(NSInteger)position {
if (position == SEDraggableLocationPositionDetermineAutomatically) {
if (self.shouldKeepObjectsArranged) {
position = self.containedObjects.count - 1;
CGPoint p = [self calculateCenterOfDraggableObject:object inPosition:position];
return [self convertPoint:p toView:nil]; // return point in window coords
}
else {
// return the center point
CGPoint p = [object getCenterInWindowCoordinates];
if (CGPointEqualToPoint(p, CGPointZero))
return [self getCenterInWindowCoordinates];
else
return p;
}
}
else {
CGPoint p = [self calculateCenterOfDraggableObject:object inPosition:position];
return [self convertPoint:p toView:nil]; // return point in window coords
}
}
- (void) recalculateAllObjectPositions {
__block SEDraggableLocation *myself = self;
void (^blockRecalculate)() = ^{
NSUInteger index = 0;
unsigned int iseed = (unsigned int)time(NULL);
srand(iseed);
double max = RAND_MAX;
double irand;
double mult = myself.randomArrangementOffsetMultiplier;
for (SEDraggable *object in myself.containedObjects) {
CGPoint centerInWindowCoords = [myself getAcceptableWindowCoordsForDraggableObject:object inPosition:index];
CGPoint centerInLocalCoords = [myself convertPoint:centerInWindowCoords fromView:nil];
index++;
irand = (double)rand();
centerInLocalCoords.x += (CGFloat)((irand / max) * mult) - (mult / 2);
centerInLocalCoords.y += (CGFloat)((irand / max) * mult) - (mult / 2);
[object setCenter:centerInLocalCoords];
if ([myself.delegate respondsToSelector:@selector(draggableLocation:didMoveObject:)])
[myself.delegate draggableLocation:myself didMoveObject:object];
}
};
void (^blockCompletion)(BOOL) = ^(BOOL finished) {
if ([myself.delegate respondsToSelector:@selector(draggableLocationDidRecalculateObjectPositions:)])
[myself.delegate draggableLocationDidRecalculateObjectPositions:myself];
};
if (self.shouldAnimateObjectAdjustments) {
[UIView animateWithDuration:self.animationDuration delay:self.animationDelay options:self.animationOptions
animations:blockRecalculate completion:blockCompletion];
}
else {
blockRecalculate();
blockCompletion(YES);
}
}
- (BOOL) pointIsInsideResponsiveBounds:(CGPoint)point {
CGPoint localPoint = [self.responsiveBounds convertPoint:point fromView:nil];
BOOL inside = [self.responsiveBounds pointInside:localPoint withEvent:nil];
return inside;
}
#pragma mark- Entry decision handlers
/**
* If you pass a draggable that:
* 1) has superview == nil
* a) but has coordinates in self.center:
* -- it will be assumed that those coordinates are already in the coordinate system of this SEDraggableLocation
* b) does not have coordinates in self.center:
* -- it will be up to the SEDraggableLocation (or subclass) to decide upon good coordinates (in getAcceptableLocationForDraggableObject:inPosition:)
* 2) has a superview, i.e., superview != nil
* a) -- it's assumed that it will have coordinates, so its movement will be calculated by converting the draggable's 'center' property in the superview's coordinate system to this SEDraggableLocation's coordinate system
*/
- (void) acceptDraggableObject:(SEDraggable *)draggable
entryMethod:(SEDraggableLocationEntryMethod)entryMethod
animated:(BOOL)animated {
/**
* either:
* 1. (existing draggable case) the draggable has a superview (i.e. previous location) and also coordinates,
* 2. (new draggable case) the draggable has just been newly added and has no superview and no coordinates, or
* 3. (loading a saved draggable case) the draggable has been newly added and has no superview but does have coordinates
*/
// existing draggable case
if (entryMethod != SEDraggableLocationEntryMethodWasAdded && draggable.superview != nil) {
// convert 'center' over to the receiver view's coordinate system in advance
CGPoint draggableCenterInWindowCoords = [draggable getCenterInWindowCoordinates];
CGPoint draggableCenterInReceiverCoords = [self convertPoint:draggableCenterInWindowCoords fromView:nil];
draggable.center = draggableCenterInReceiverCoords;
}
// new draggable case
else if (entryMethod == SEDraggableLocationEntryMethodWasAdded && draggable.superview == nil && CGPointEqualToPoint(draggable.center, CGPointZero)) {
CGPoint draggableCenterInWindowCoords = draggable.center;
CGPoint draggableCenterInReceiverCoords = [self convertPoint:draggableCenterInWindowCoords fromView:nil];
draggable.center = draggableCenterInReceiverCoords;
}
// loading a saved draggable case
else if (entryMethod == SEDraggableLocationEntryMethodWasAdded && draggable.superview == nil && !CGPointEqualToPoint(draggable.center, CGPointZero)) {
// 'center' should be in the receiver's local coordinate system already, so no conversion is needed
// (no-op)
}
if (draggable.currentLocation != self) {
[self.containedObjects addObject:draggable];
draggable.previousLocation = draggable.currentLocation;
draggable.currentLocation = self;
[draggable.previousLocation removeDraggableObject:draggable];
}
// add the draggable to its new parent view
[self addSubview:draggable];
CGPoint destinationPointInWindowCoords = [self getAcceptableWindowCoordsForDraggableObject: draggable
inPosition: SEDraggableLocationPositionDetermineAutomatically];
CGPoint destinationPointInLocalCoords = [self convertPoint:destinationPointInWindowCoords fromView:nil];
__block SEDraggableLocation *myself = self;
__block SEDraggable *blockDraggable = draggable;
void (^completionBlock)(BOOL) = ^(BOOL finished) {
if (myself.shouldKeepObjectsArranged)
[myself recalculateAllObjectPositions];
// notify the draggable
if ([blockDraggable respondsToSelector:@selector(draggableLocation:didAllowEntry:animated:)])
[blockDraggable draggableLocation:myself didAllowEntry:entryMethod animated:animated];
// notify my delegate
if ([myself.delegate respondsToSelector:@selector(draggableLocation:didAcceptObject:entryMethod:)])
[myself.delegate draggableLocation:myself didAcceptObject:blockDraggable entryMethod:entryMethod];
};
if (animated) {
[draggable snapCenterToPoint:destinationPointInLocalCoords animated:animated completion:completionBlock];
}
else {
draggable.center = destinationPointInLocalCoords;
completionBlock(YES);
}
}
- (void) refuseDraggableObject:(SEDraggable *)draggable
entryMethod:(SEDraggableLocationEntryMethod)entryMethod
animated:(BOOL)animated {
// notify the draggable
[draggable draggableLocation:self didRefuseEntry:entryMethod animated:animated];
// notify delegate
if ([self.delegate respondsToSelector:@selector(draggableLocation:didRefuseObject:entryMethod:)])
[self.delegate draggableLocation:self didRefuseObject:draggable entryMethod:entryMethod];
}
- (void) removeDraggableObject:(SEDraggable *)draggable {
if (draggable.currentLocation == self) {
draggable.previousLocation = draggable.currentLocation;
draggable.currentLocation = nil;
}
[self.containedObjects removeObject:draggable];
if (draggable.superview == self)
[draggable removeFromSuperview];
if ([self.delegate respondsToSelector:@selector(draggableObject:wasRemovedFromLocation:)])
[self.delegate draggableObject:draggable wasRemovedFromLocation:self];
if (self.shouldKeepObjectsArranged)
[self recalculateAllObjectPositions];
}
#pragma mark- NSCoding
- (void)encodeWithCoder:(NSCoder *)encoder {
[super encodeWithCoder:encoder];
[encoder encodeFloat:self.objectWidth forKey:kOBJECT_WIDTH_KEY];
[encoder encodeFloat:self.objectHeight forKey:kOBJECT_HEIGHT_KEY];
[encoder encodeFloat:self.marginLeft forKey:kMARGIN_LEFT_KEY];
[encoder encodeFloat:self.marginRight forKey:kMARGIN_RIGHT_KEY];
[encoder encodeFloat:self.marginTop forKey:kMARGIN_TOP_KEY];
[encoder encodeFloat:self.marginBottom forKey:kMARGIN_BOTTOM_KEY];
[encoder encodeFloat:self.marginBetweenX forKey:kMARGIN_BETWEEN_X_KEY];
[encoder encodeFloat:self.marginBetweenY forKey:kMARGIN_BETWEEN_Y_KEY];
[encoder encodeFloat:self.randomArrangementOffsetMultiplier forKey:kRANDOM_ARRANGEMENT_OFFSET_MULTIPLIER_KEY];
[encoder encodeObject:self.responsiveBounds forKey:kRESPONSIVE_BOUNDS_KEY];
[encoder encodeObject:self.objectGutterBounds forKey:kOBJECT_GUTTER_BOUNDS_KEY];
[encoder encodeBool:self.shouldAcceptDroppedObjects forKey:kSHOULD_ACCEPT_DROPPED_OBJECTS_KEY];
[encoder encodeBool:self.shouldAcceptObjectsSnappingBack forKey:kSHOULD_ACCEPT_OBJECTS_SNAPPING_BACK_KEY];
[encoder encodeBool:self.shouldKeepObjectsArranged forKey:kSHOULD_KEEP_OBJECTS_ARRANGED_KEY];
[encoder encodeBool:self.shouldAnimateObjectAdjustments forKey:kSHOULD_ANIMATE_OBJECT_ADJUSTMENTS_KEY];
[encoder encodeBool:self.shouldHighlightOnDragOver forKey:kSHOULD_HIGHLIGHT_ON_DRAG_OVER_KEY];
[encoder encodeObject:[UIColor colorWithCGColor:self.highlightColor] forKey:kHIGHLIGHT_COLOR_KEY];
[encoder encodeFloat:self.highlightOpacity forKey:kHIGHLIGHT_OPACITY_KEY];
[encoder encodeFloat:self.animationDuration forKey:kANIMATION_DURATION_KEY];
[encoder encodeFloat:self.animationDelay forKey:kANIMATION_DELAY_KEY];
#warning //ivar named: animationOptions and of type: UIViewAnimationOptions -- TYPE_NOT_SUPPORTED
#warning //[encoder encodeType(?):self.animationOptions forKey:kANIMATION_OPTIONS_KEY];
[encoder encodeBool:self.fillHorizontallyFirst forKey:kFILL_HORIZONTALLY_FIRST_KEY];
[encoder encodeBool:self.allowRows forKey:kALLOW_ROWS_KEY];
[encoder encodeBool:self.allowColumns forKey:kALLOW_COLUMNS_KEY];
[encoder encodeObject:self.delegate forKey:kDELEGATE_KEY];
[encoder encodeObject:self.containedObjects forKey:kCONTAINED_OBJECTS_KEY];
}
- (id)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (self) {
[self defaultAllOwnProperties];
if ([decoder containsValueForKey:kOBJECT_WIDTH_KEY])
self.objectWidth = [decoder decodeFloatForKey:kOBJECT_WIDTH_KEY];
if ([decoder containsValueForKey:kOBJECT_HEIGHT_KEY])
self.objectHeight = [decoder decodeFloatForKey:kOBJECT_HEIGHT_KEY];
if ([decoder containsValueForKey:kMARGIN_LEFT_KEY])
self.marginLeft = [decoder decodeFloatForKey:kMARGIN_LEFT_KEY];
if ([decoder containsValueForKey:kMARGIN_RIGHT_KEY])
self.marginRight = [decoder decodeFloatForKey:kMARGIN_RIGHT_KEY];
if ([decoder containsValueForKey:kMARGIN_TOP_KEY])
self.marginTop = [decoder decodeFloatForKey:kMARGIN_TOP_KEY];
if ([decoder containsValueForKey:kMARGIN_BOTTOM_KEY])
self.marginBottom = [decoder decodeFloatForKey:kMARGIN_BOTTOM_KEY];
if ([decoder containsValueForKey:kMARGIN_BETWEEN_X_KEY])
self.marginBetweenX = [decoder decodeFloatForKey:kMARGIN_BETWEEN_X_KEY];
if ([decoder containsValueForKey:kMARGIN_BETWEEN_Y_KEY])
self.marginBetweenY = [decoder decodeFloatForKey:kMARGIN_BETWEEN_Y_KEY];
if ([decoder containsValueForKey:kRANDOM_ARRANGEMENT_OFFSET_MULTIPLIER_KEY])
self.randomArrangementOffsetMultiplier = [decoder decodeFloatForKey:kRANDOM_ARRANGEMENT_OFFSET_MULTIPLIER_KEY];
if ([decoder containsValueForKey:kRESPONSIVE_BOUNDS_KEY])
self.responsiveBounds = [decoder decodeObjectForKey:kRESPONSIVE_BOUNDS_KEY];
if ([decoder containsValueForKey:kOBJECT_GUTTER_BOUNDS_KEY])
self.objectGutterBounds = [decoder decodeObjectForKey:kOBJECT_GUTTER_BOUNDS_KEY];
if ([decoder containsValueForKey:kSHOULD_ACCEPT_DROPPED_OBJECTS_KEY])
self.shouldAcceptDroppedObjects = [decoder decodeBoolForKey:kSHOULD_ACCEPT_DROPPED_OBJECTS_KEY];
if ([decoder containsValueForKey:kSHOULD_ACCEPT_OBJECTS_SNAPPING_BACK_KEY])
self.shouldAcceptObjectsSnappingBack = [decoder decodeBoolForKey:kSHOULD_ACCEPT_OBJECTS_SNAPPING_BACK_KEY];
if ([decoder containsValueForKey:kSHOULD_KEEP_OBJECTS_ARRANGED_KEY])
self.shouldKeepObjectsArranged = [decoder decodeBoolForKey:kSHOULD_KEEP_OBJECTS_ARRANGED_KEY];
if ([decoder containsValueForKey:kSHOULD_ANIMATE_OBJECT_ADJUSTMENTS_KEY])
self.shouldAnimateObjectAdjustments = [decoder decodeBoolForKey:kSHOULD_ANIMATE_OBJECT_ADJUSTMENTS_KEY];
if ([decoder containsValueForKey:kSHOULD_HIGHLIGHT_ON_DRAG_OVER_KEY])
self.shouldHighlightOnDragOver = [decoder decodeBoolForKey:kSHOULD_HIGHLIGHT_ON_DRAG_OVER_KEY];
if ([decoder containsValueForKey:kHIGHLIGHT_COLOR_KEY])
self.highlightColor = ((UIColor *)[decoder decodeObjectForKey:kHIGHLIGHT_COLOR_KEY]).CGColor;
if ([decoder containsValueForKey:kHIGHLIGHT_OPACITY_KEY])
self.highlightOpacity = [decoder decodeFloatForKey:kHIGHLIGHT_OPACITY_KEY];
if ([decoder containsValueForKey:kANIMATION_DURATION_KEY])
self.animationDuration = [decoder decodeFloatForKey:kANIMATION_DURATION_KEY];
if ([decoder containsValueForKey:kANIMATION_DELAY_KEY])
self.animationDelay = [decoder decodeFloatForKey:kANIMATION_DELAY_KEY];
#warning //ivar named: animationOptions and of type: UIViewAnimationOptions -- TYPE_NOT_SUPPORTED
#warning //[self setAnimationOptions:[decoder decodeType(?)ForKey:kANIMATION_OPTIONS_KEY]];
if ([decoder containsValueForKey:kFILL_HORIZONTALLY_FIRST_KEY])
self.fillHorizontallyFirst = [decoder decodeBoolForKey:kFILL_HORIZONTALLY_FIRST_KEY];
if ([decoder containsValueForKey:kALLOW_ROWS_KEY])
self.allowRows = [decoder decodeBoolForKey:kALLOW_ROWS_KEY];
if ([decoder containsValueForKey:kALLOW_COLUMNS_KEY])
self.allowColumns = [decoder decodeBoolForKey:kALLOW_COLUMNS_KEY];
if ([decoder containsValueForKey:kDELEGATE_KEY])
self.delegate = [decoder decodeObjectForKey:kDELEGATE_KEY];
if ([decoder containsValueForKey:kCONTAINED_OBJECTS_KEY])
self.containedObjects = [decoder decodeObjectForKey:kCONTAINED_OBJECTS_KEY];
}
return self;
}
- (id)copyWithZone:(NSZone *)zone {
id theCopy = [[[self class] allocWithZone:zone] initWithFrame:self.frame]; // use designated initializer
[theCopy setObjectWidth:self.objectWidth];
[theCopy setObjectHeight:self.objectHeight];
[theCopy setMarginLeft:self.marginLeft];
[theCopy setMarginRight:self.marginRight];
[theCopy setMarginTop:self.marginTop];
[theCopy setMarginBottom:self.marginBottom];
[theCopy setMarginBetweenX:self.marginBetweenX];
[theCopy setMarginBetweenY:self.marginBetweenY];
[theCopy setRandomArrangementOffsetMultiplier:self.randomArrangementOffsetMultiplier];
[theCopy setResponsiveBounds:self.responsiveBounds];
[theCopy setObjectGutterBounds:self.objectGutterBounds];
[theCopy setShouldAcceptDroppedObjects:self.shouldAcceptDroppedObjects];
[theCopy setShouldAcceptObjectsSnappingBack:self.shouldAcceptObjectsSnappingBack];
[theCopy setShouldKeepObjectsArranged:self.shouldKeepObjectsArranged];
[theCopy setShouldAnimateObjectAdjustments:self.shouldAnimateObjectAdjustments];
[theCopy setShouldHighlightOnDragOver:self.shouldHighlightOnDragOver];
[theCopy setHighlightColor:self.highlightColor];
[theCopy setHighlightOpacity:self.highlightOpacity];
//[theCopy setAnimationDuration:self.animationDuration];
[theCopy setAnimationDelay:self.animationDelay];
[theCopy setAnimationOptions:self.animationOptions];
[theCopy setFillHorizontallyFirst:self.fillHorizontallyFirst];
[theCopy setAllowRows:self.allowRows];
[theCopy setAllowColumns:self.allowColumns];
//[theCopy setDelegate:self.delegate];
[theCopy setContainedObjects:self.containedObjects];
return theCopy;
}
@end