UIView take away first responder status

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!!!


您可以尝试在视图中覆盖canBecomeFirstResponder ,并在适当的时候返回适当的值。


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.

链接地址: http://www.djcxy.com/p/7698.html

上一篇: 在失去专注于uisearchbar的情况下辞职键盘

下一篇: UIView带走第一响应者状态