UIScrollview subviews not recognizing pan gesture after zooming - ios

I have a scrollview to which I have added an image view as a subview. The contentsize of the scrollview is same as the size of the imageview (width and height). There are two buttons outside the scrollview. When I click on either on them, a small rectangle view is added as a subview to the imageview. This rectangle view can be dragged anywhere on the imageview by the user after it has been added.
This works fine until I pinch to zoom the scrollview. In the viewForZoomingInScrollView: method, I return the imageview and the zooming works fine. But in the zoomed view when I try to drag around the rectangle view, it does not move. It does not recognize the pan gestures any more. Any idea why this is happening?
This Dragable view is too small and I have to change its position so I am zomming scrollview to touchable view.

I think you should do this:
Inform the delegate when the zoom is finished by calling:scrollViewDidEndZooming:withView:atScale:
in this method you update the parent view of the view where the rectangle can move or may be something else.....but you have to update something in this method....please put your specific code where the problem is.

Related

UIScrollView Zoom on shake effect

I am working on application in which i need to zoom the scroll view on shake effect so user will not touch the screen to pinch or double tap.
I have implemented the code by looking in to this tutorial:
Zoom UIScrollView with multiple images
I got the call in a delegate:
viewForZoomingInScrollView
But the image view not zoom in or out.
When i touch the screen after the delegate called the scroll view is zoom in. But content in scroll view not zoom in or out. It remains as it is.
Even some time i did not get call in the following delegate:
scrollViewDidZoom
scrollViewDidEndZooming
So do i need to call layout subview after viewForZoomingInScrollView if yes where?
From my understanding the view is not zooming because i have not pinch or double tap the scroll view.
Please help me out.
Those you mentioned are UIScrollView delegate methods and they are called when the scrollView will\did actually zoom, not to perform the zooming.
To perform the zoom programmatically you need to use zoomToRect:animated: and passing the portion of your scorllView's subview you want to scroll and wether it needs to be animated or not.
Hope it helps.

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.

How can I place a non-scrolling UIView underneath the scroll indicators on a UIScrollView?

I have an application where I'm using a zooming scrollView to do image cropping to a rectangle with a fixed aspect ratio. I have a mask where I darken the parts of the image that will be cropped. Currently I add this subview to the UIScrollView's parent, making them siblings, where this mask is 'higher' than the scrollview. Looks great. Except...
This mask is also masking the scrollIndicators and therefore looks a bit dumb. I could turn off the scrollIndicators, or, ideally, I'd like to place this UIView underneath the scrollIndicators, but not get scrolled with other content, which is what would happen if I made it a subview of the scrollview via [scrollView addSubview: myMaskView];
Anyone know if this is possible?
First, subclass UIScrollView so that you can modify the default behavior of scroll view.
Second create an image view with your image, and put both the image view and your mask view to a scroll view, this way your views will be underneath the scroll indicator.
Third, in your scroll view delegate method viewForZoomingInScrollView:, return your image view, so that only the image view zooms. Note that the scroll view will adjust the content size to be the size of the returned view, but it's fine as long as your image view takes up the whole content size.
And last, override layoutSubviews method, move the mask view to visible bounds of scroll view. The layoutSubviews method is said to be called every frame of scrolling, so the position change won't be visible to end user.
For more details you can refer WWDC session video "Advanced ScrollView Techniques".
EDIT: OK, just found that you can avoid overriding layoutSubviews by implementing the delegate method scrollViewDidScroll.

How do you receive touches in views added to a subview

I have been adding several subviews ("touch subviews") to a scroll view which respond to touches. The touch delegate methods in each of these subviews all fire nicely.
I have one subview (bodyClock) which holds the main content of the scroll view and is the viewForZoomingInScrollView. In order for the "touch" subviews to zoom properly I find now that I have to add them the bodyClock subview instead of the scroll view. When I do this, however, the "touch subviews" no longer respond to touches.
I have tried all sort of things with first responder without any success. Any help pointing me in the right direction would be appreciated.
OK, I found my problem I had a subview acting as a time mask in the scroll view that I think was responding to touches. This became evident when I noticed that the touch subViews did not respond to touches while the mask was over them. Because the mask was a subview to the scroll view, it would move when zooming such that a touch subview in the bodyClock view would come out from underneath the mask and suddenly start working.
Moving the mask from the scroll view to the bodyClock subView along with the "touch subviews" fixed my problem. Now all the subviews scroll and zoom properly, and respond to touches.

Resources