Go through this video !
If you need to implement as illustrated in video, This post is for you.
1. Open your project.
2. Add a view & imageView as illustrated in following image.
3. Place them properly.
4. User would be swiping.
So, we would be needing touch-begin to determine the valid touch.
touch-move to move frames of objects.
touch-end to apply final animation.
Go through comments within code to understand it.
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 |
// touch-begin to determine the valid touch - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self.view]; CGRect rect = self.imgV.frame; BOOL xRange = point.x >= rect.origin.x && point.x< =rect.origin.x+rect.size.width; BOOL yRange = point.y >= rect.origin.y && point.y< =rect.origin.y+rect.size.height; if(xRange && yRange) { self.slidingView=YES; } } // touches-move to move the objects accordingly touch - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if([self isSlidingView]) { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self.view]; CGRect rect = self.imgV.frame; if((point.y-rect.size.height/2)<0) { point = CGPointMake(point.x,rect.size.height/2); } else if(((point.y+rect.size.height/2)>self.view.frame.size.height)) { point = CGPointMake(point.x,self.view.frame.size.height-rect.size.height/2); } CGRect newRect = CGRectMake(rect.origin.x, point.y-rect.size.height/2, rect.size.width, rect.size.height); self.imgV.frame=newRect; self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height); } } // touches ended - for final animation - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if([self isSlidingView]) { self.slidingView=NO; UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self.view]; [UIView beginAnimations:@"move" context:nil]; [UIView setAnimationDuration:0.5]; if(point.y>(self.view.frame.size.height-self.view.frame.size.height/2)) { self.imgV.frame=CGRectMake(0, self.view.frame.size.height-self.imgV.frame.size.height, self.imgV.frame.size.width, self.imgV.frame.size.height); } else { self.imgV.frame=CGRectMake(0, 0, self.imgV.frame.size.width, self.imgV.frame.size.height); } self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height); [UIView commitAnimations]; } } |
i want to use it in Storynoard so please refer me for that
For this you need to include auto layout and that view added into story board and you need deal with constraint rather then frame.
can you send me code for the same
Already source code attached here.
Source code doesn’t work. I try to create a new project, with same elements and using your code, but nothing move’s. Sample cod give me error : “The operation couldn’t be completed. (LaunchServicesError error 0.) “
Thank you for visit sugartin.info
Yes,Here is the link for solve your problem now you can test this project.
https://sourceforge.net/projects/nimitparekh/files/Sliding%20Demo/SlidingDemo.zip/download
May helps lot.