SWView
Swipe-able View. View can be swiped and has UIDynamics to animate it off screen or 'snap' back to it's origin.
Designed to be very lightweight and easy to integrate. For usage example see below:
//Initialse the view with a frame, I have used the current view's center as my snap point.
SWView *svView = [[SWView alloc] initWithFrame:YOUR_FRAME andSnapPoint:self.view.center fromRootView:self.view];
[self.view addSubview:svView];
[svView setupCollisionBehaviourWithDelegate:self];
You can then implement:
- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id )item withBoundaryIdentifier:(id )identifier atPoint:(CGPoint)p
- (void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id )item withBoundaryIdentifier:(id )identifier
To listen for when the view collides with the boundary.
In my implementation I do the following:
-(void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id )item withBoundaryIdentifier:(id )identifier {
//Get the SWView:
if ([item isKindOfClass:[SWView class]]) {
[behavior removeItem:item];
[(SWView *)item removeFromSuperview];
}
}
To have the view ‘drop’ out of sight with a slight animation simply use:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
//Create new instance of SWView
SWView *swView = nil;
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[SWView class]]) {
//This is our view:
swView = (SWView *) view;
if ([view.layer.presentationLayer hitTest:touchLocation])
return;
}
}
[swView enableGravityFromSide:touchLocation.x < (self.view.frame.size.width / 2)];
}
Log in or sign up for Devpost to join the conversation.