Skip to content

Commit 6bb6311

Browse files
committed
Lecture 8 - Dropit : adding collision behaviour
now the blocks gets stacked at the bottom and on the top of one another.
1 parent 394eff5 commit 6bb6311

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Dropit/Dropit/DropitViewController.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ @interface DropitViewController ()
1212
@property (weak, nonatomic) IBOutlet UIView *gameView;
1313
@property (strong, nonatomic) UIDynamicAnimator *animator;
1414
@property (strong, nonatomic) UIGravityBehavior *gravity;
15+
@property (strong, nonatomic) UICollisionBehavior *collider;
1516
@end
1617

1718
@implementation DropitViewController
@@ -36,6 +37,16 @@ - (UIGravityBehavior *)gravity
3637
return _gravity;
3738
}
3839

40+
- (UICollisionBehavior *)collider
41+
{
42+
if (!_collider) {
43+
_collider = [[UICollisionBehavior alloc] init];
44+
_collider.translatesReferenceBoundsIntoBoundary = YES;
45+
[self.animator addBehavior:_collider];
46+
}
47+
return _collider;
48+
}
49+
3950
- (IBAction)tap:(UITapGestureRecognizer *)sender
4051
{
4152
[self drop];
@@ -54,6 +65,7 @@ - (void)drop
5465
[self.gameView addSubview:dropView];
5566

5667
[self.gravity addItem:dropView];
68+
[self.collider addItem:dropView];
5769
}
5870

5971
- (UIColor *)randomColor

0 commit comments

Comments
 (0)