- (IBAction)panLayer:(UIPanGestureRecognizer *)pan
{
if(pan.state == UIGestureRecognizerStateChanged)
{
CGPoint point = [pan translationInView:topLayer];
CGRect frame = topLayer.frame;
frame.origin.x = layerPosition + point.x;
if(frame.origin.x + 320 > 320) frame.origin.x = 0;
topLayer.frame = frame;
}
if (pan.state == UIGestureRecognizerStateEnded) {
if (topLayer.frame.origin.x +320 <= 260) {
[self animateLayerToPoint:-180];
}
else
{
[self animateLayerToPoint:0];
}
}
}
-(void)animateLayerToPoint:(CGFloat)x
{
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect frame = topLayer.frame;
frame.origin.x = x;
topLayer.frame = frame;
}completion:^(BOOL finished) {
self.layerPosition = topLayer.frame.origin.x;
}];
}
Hope this helps...