After scroll visible coordinates for the objects in the UIScrollView - ios

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

Related

UIScrollView automatically scrolls to next subview horizontally then bounces somewhere else

UIScrollView has several UILabel subviews, which are set to scroll horizontally (think about Instagram filters scrolling view). I can scroll UIScrollSubview, act upon tapping on a UILabel subview. Next thing I would like to achieve is to programmatically scroll to an invisible UILabel subview, when the users selects the last visible subview on the right (similar to how the instagram filters scroll out of the visible area when the user selects the last visible filter).
When the user touches the last visible UILabel subview, I execute
[_scrollView setContentOffset:CGPointMake(64, 0) animated:YES];
where 64 is the width of every UILabel subview of the scrollView.
This works fine only on the first selection event of the last visible subview. Once the scrollView scrolled to reveal the desired subview on the right side of the selected one, and I select newly revealed subview, the scrollView correctly scrolls to the left revealing the next invisible subview, but then jumps back (to the right) two positions (128). The desired behaviour is to always scroll to the left when the last visible subview on the right is selected (right now this happens only on the first selection).
Any suggestions would be appreciated.
Thanks.
EDIT: The bouncing issue went away in 2 cases:
scrollView.pagingEnabled: NO;
user performs relatively long touches on subviews
You should add 64 to the current contentOffset.
[_scrollView setContentOffset:CGPointMake(_scrollView.contentOffset.x + 64, 0) animated:YES];

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

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.

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.

Animate objects when UIScrollView scrolls

I have a UIScrollView which has two pages and only scroll horizontally.
The scrolling and paging is controlled using a UIPageControl. I have placed a UIImageView on the scrollView which contains an image of an iPhone (shown in red in the image below) that says Hello inside page 1.
I wanted to animate the UIImageView to rotate and change its position as shown in the image when the user scrolls from page-1 to page-2. Also the animation should ideally rotate back when the user is scrolling back from page-2 to page-1.
The animation or movement of the UIImageView is based on how much the user is scrolling horizontally and not based on time.
How can I rotate the UIImageView back and forth based on the scroll position of the UIScrollView?
Set a delegate for your scroll view. Probably you want your view controller to be the delegate. You need to add UIScrollViewDelegate to its list of protocols.
Then, in the delegate, implement scrollViewDidScroll:. In scrollViewDidScroll:, look at the scroll view's contentOffset. Based on the contentOffset, set the image view's transform and center to rotate and move it where you want.
To find by how much the scroll view has scrolled, you can check UIScrollView's contentOffset property:
contentOffset - The point at which the origin of the content view is
offset from the origin of the scroll view.
Then to rotate that image view, you could do this:
self.imageview.transform = CGAffineTransformMakeRotation(M_PI/2);
As far as the animation goes, I personally don't have much experience with it. But you could have a look at Simple Animation Using UIImageView.

IOS UIScrollView - scroll and click element at the same time

I have a UIScrollView with an button just outside the content area of the scrollView. The user has to scroll up and hold the spring effect which one finger and push the button with another finger. The problem is that the touch on the button is never detected.
Please see the illustration below
The scroll view in it's initial state. the orange area is the scrollView, the white area the button
The user is now scrolling and holding with one finger to overcome the spring effect of the UIScrollView, and want to click the button
Any suggestions?
Check this out:
UIScrollView blocks all touches while zooming or scrolling
Make sure you have multitouch set to YES on the scrollview and also don't have any subviews with exclusive touch enabled.

Resources