How do we hinder a red "Barrier"s that are a red elements from relocating
while permitting a "falling" elements (UIView* square) to tumble and
correlate with a barrier(s)?There are many gray elements, many red
barriers...@interface MainViewController (){ UIDynamicAnimator*
_animator; UIGravityBehavior* _gravity;
UICollisionBehavior* _collision; // NSMutableArray
*collisionArray;}@end@implementation MainViewController -
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle
*)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil
bundle:nibBundleOrNil]; if (self) { //
} relapse self;}- (void)viewDidLoad{ [super
viewDidLoad]; // collisionArray = [[NSMutableArray
alloc] init]; _animator = [[UIDynamicAnimator alloc]
initWithReferenceView:self.view]; [self
addTheBarrier];}-(void)addTheBarrier{ for (int i=0; i<20; i++)
{ UIView* separator = [[UIView alloc]
initWithFrame:CGRectMake(i*16, 250, 10, 10)];
barrier.backgroundColor = [UIColor redColor]; [self.view
addSubview:barrier]; CGPoint rightEdge =
CGPointMake(barrier.frame.origin.x +
barrier.frame.size.width, barrier.frame.origin.y);
[_collision addBoundaryWithIdentifier:@"barrier"
fromPoint:barrier.frame.origin
toPoint:rightEdge]; [collisionArray
addObject:barrier]; } [self startDynamic]; }
#pragma symbol - Dynamics -(void)startDynamic {
UIView* retard = [[UIView alloc]
initWithFrame:CGRectMake((arc4random()%250)+10, 100, 10, 10)];
square.backgroundColor = [UIColor grayColor]; [self.view
addSubview:square]; [collisionArray addObject:square];
_collision = [[UICollisionBehavior alloc]
initWithItems:collisionArray]; _gravity =
[[UIGravityBehavior alloc] initWithItems:@[square]];
[_animator addBehavior:_gravity]; //
UIDynamicItemBehavior* itemBehaviour = [[UIDynamicItemBehavior alloc]
initWithItems:@[square]]; itemBehaviour.elasticity = 0.85;
[_animator addBehavior:itemBehaviour]; //
UIPushBehavior *push = [[UIPushBehavior alloc] initWithItems:@[
retard ] mode:UIPushBehaviorModeContinuous]; [push
setPushDirection:CGVectorMake(0, 0)]; [_animator
addBehavior:push]; [_collision
setTranslatesReferenceBoundsIntoBoundary:NO]; [_animator
addBehavior:_collision]; [self
performSelector:@selector(startDynamic) withObject:nil afterDelay:0.3
];}@end
No comments:
Post a Comment