Vertical Sliding of xib while we drag using finger using Objective-C - ios

I have a Main view(currently displayed view).
AnotherView is added as a subview to a scrollview.The initial position of this AnotherView has to be in such a way that the bottom of this another view appears on the top most portion of the MainView.
Now,when I drag the AnotherView's bottom portion downwards,AnotherView should get displayed as SLIDING from top to bottom with the speed I drag it.
When I stop dragging,the sliding also should halt.
If I release the dragging after half of the screen,the sliding should continue to bottom of the screen.
How could I achieve this ?

You should use UIPanGestureRecognizer.
AnotherView should be in front of main or put it to front in Pan recogniser's function on UIGestureRecognizerStateBegan.
If UIGestureRecognizerStateChanged change anotherView frame accordingly to this movement. You can get movement by [panRecognizer translationInView:self.view] which returns CGPoint. And check if Another view is already after half of the screen. If you pass half of the screen, just use animateWithDuration to finish movement on UIGestureRecognizerStateEnded.
So another view doesn't need to be inside scrollview.
As far as I understood, you want to make something similar to sliding out menu. http://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path
There you can find example how to use pan recognizer to slide view by dragging.

Related

Is there a way to exit the current view group while using pan gesture in ios?

So I have a horizontal scroll view at the bottom of my screen which contains child views. I would like to drag a view from the bottom and snap it to a defined position on the top. But while dragging the view, it only moves about inside the scroll view. Is there any way to exit the scrollview and get the view outside it?
Layout of the app (I want to take the items from the bottom and snap them to the positions on top):
When you try moving views coordinates with drag, it will only move on its superview, i.e. your bottom scroll view.
If you wanted to drag your button outside of your scroll view then you need to have a trick here.
When user started dragging the button, hide it.
Add the same layout button on main screen on exact position.
Move the newly added button on main screen where ever you want.
Once you drop it, remove the old scroll view button.
It will look like you dragged the same button on main screen but under the hood it was a different logic.

How to make a UIScrollView, some UIButtons and UIPanGestureRecognizer work together?

I got a scroll view with a bunch of buttons, which I want to both touch and drag.
To choose if it's a touch or a drag (not drag of the scroll view, "physically" dragging the button), I check the pan gesture recognizer of the button to see how far away the drag would be, if it's over a threshold I snap the button into drag mode and, removing it from the scroll view and adding it to my view controller's view (at the same location, so looks like it's in the same place).
This all works kinda smooth, except when I want to scroll and the pan fires at the same time. I need a way for the pan gesture recognizer to choose, based on velocity, if the scroll view should scroll or the button should be dragged.
The question: Is there a way for a UIPanGestureRecognizer to tell a UIScrollView to continue scrolling and cancel itself?

Which the better way to make carousel view in swift with open - animation (expanding)?

I need to make carousel view in swift with "opening-animation".
First of all, I have created scroll view, after that have created subViews with my customView, maked my scrollView paged-enabled, and it's okay, but I need to make it expanding by swipe gesture. I added animation, but this view can't be higher than scrollView height, so I need to make this width and height (after gesture) like viewController's view height and width. And, it's the problem.
What's better way to do this?
Example screen:
BeforeGesture
Second example screen: after up-swipe gesture
I think you will need to handle it using the UIPanGestureRecognizer gesture which will give you the better control on all the different states of pan (drag began, drag ended). In your drag ended state you can handle the logic of increasing the height of scrollview and after that add the animation to show the expanded view with animation effect.
Let me know if you need any further help.

Pass touches from a UIView to UIScrollView beneath it

I have a UIScrollView stretching over the entire screen, which the user is able to scroll vertically only. Right 'above' it is a UIView with a few buttons, which covers the bottom 120 px only. The user may tap the buttons to invoke their selectors. But I wish to be able to pass the panning movement to the scrollView, so that the user may scroll the scrollView if they pan with a velocity greater than a certain threshold, if the panning begins over the UIView.
How would I go about it?
Thanks
You can do 2 things.
Add a UITouchesMoved function to your uiView, calculate finger movement and move your scrollView accordingly by scrolling it to a CGPoint.
You can use UIPanGestureRecognizer.

After scroll visible coordinates for the objects in the UIScrollView

I have a UIScrollView which contains 12 buttons. Only 5 buttons are visible at a time and rest all are not. When user clicks on a button i am animating a UIView from the position of the button. So when I scroll for hidden buttons and click view animation start from bottom from its original coordinates but not from the visible coordinates of the button.
When user scroll i want to know the visible coordinates of the button (contained in uiscrollview), so that I can animate from the button visible position. Or can anybody suggest which is the best way to implement this animation.
Note: My Scrollview is part of viewcontroller. I can't customize the scrollview as a parent class. Please help me asap to solve it as i am at the end of application development.
I just solved it using Scrollview convertPoint:toView API. Here is the solution:
CGPoint aPtInScrollView = [viewA convertPoint:aPoint toView:self.view];
Where aPoint is the object in scrollview 'position

Resources