UIView take away first responder status

896 views Asked by At

Imagine the situation when you have UITableView placed into UIScrollView. If you tap on table view and begin vertical moving - UITableView become first responder and will scroll vertically. But if you will move finger horizontally - UIScrollView become first responder and will scroll horizontally.

I have similar situation but instead of UIScrollView I have simple UIView object that intercept - (void)touchesMoved: events and make moving (kinda self made ScrollView).

But how I can do the same trick that UIScrollView do - determine horizontal moving and take away first responder status from UITableView???

Thanks in advance!!!

2

There are 2 answers

2
TomSwift On

You could try overriding canBecomeFirstResponder in your view and returning the appropriate value at the appropriate time.

0
Rob On

Have you tried throwing a UIPanGestureRecodnizer on the view. You should then be able to set a @selector which will allow you to handle the event in question. Also with pan you can choose to only change the x element and leave the y element alone. Further more with the pan element attached to a view you will not have to worry about having a first responder. Pan elements can a lot of the time be used as a swiping element if you had acceleration and or deceleration. Beyond that I would say you could also add a UISwipeGestureRecognizer element left and right but I do not think you get information such as how far the user swiped meaning, if you want the screen to snap back when the user has not made it far enough to the right or left then you will not have that option. Also, swipe will not give the same effect as the UIScrollView but UIPanGestureRecognizer can, if you do a little extra coding. The extra coding would be observing the position of the x value and then using a little bit of animation for the view to snap to the right or left when the user lets go of the view. Other then that the view should and will follow the finger if you set the x properly.