About row cells in table view
contentViewIn the
UIButtonShort press does not produce a highlight effect problem
In the demo, found UITableViewCell in the UIButton short press once do not see the default effect of gray, stay a little longer to become gray, such as the official Twitter client profile picture, Weibo review like the three buttons. Weibo all kinds of client's avatar and other buttons also like this, the avatar is a lot of direct imageview plus gestures. The best thing to do with this detail is that Instagram does not have a short press of a long press, so it's a hit.
After a search, I learned that the UITableView UIScrollView subclass, which has delaysContentTouches a Boolean attribute, and the default is YES , the delay response UIScrollView sub-view of the event, in this short delay, if the touch has moved, then the response is a scrolling event, if not moved and the child view has UIControltype and the touch position is in the control, it is immediately passed and the corresponding event is triggered. So when a short press is taken UIButton , the system is judged not to be a scrolling event before it is passed to the child view control, but the animation of the highlight effect is bypassed and the event is passed directly. So only when the finger stays a little longer, the delay time is spent to see the highlight effect.
UIButtonThis delay is removed if you want the highlight effect to be displayed in a short press of a long press. Replace the default value with the following code in the place where you finished creating the table view object, or its initialization method NO .
1 |
someTableViewObject.delaysContentTouches = NO;
|
But this time again, when the finger is in the UIButton area as the starting point of the scrolling operation, UIScrollView it does not respond to the scrolling gesture.
If you want to UITableView always respond to scrolling events in all places, you need to subclass UITableView and rewrite the following methods that inherit from the parent class UIScrollView .
1234567 |
//default returns YES if view isn ' t a Uicontrol//Returns whether to cancel touches related to the content subview and start dragging. - (bool) (uiview *) Span class= "NV" >view{ //even if the touch is a Uicontrol (Subclass: UIButton), we also want to cancel the action when dragging to respond to scrolling action return yes< Span class= "P"; } /span> |
The UIScrollView comments in the header file, as well as the description of Apple's official documentation, are known because it defaults to a scrolling event if the event is UIControl returned in response to or its subclasses, even if the NO touch is moved. So let it always return YES , that is, UIScrollView touch events that appear anywhere on the screen, and can respond to scrolling events if a move occurs.
* * Processing in IOS 7
123456789 |
Where the Cell is initializedFor(IdViewInchSelf.Subviews){ If([Nsstringfromclass([View class]) isequaltostring:@ "Uitableviewcellscrollview"]) { Uiscrollview *scrollView = (uiscrollview *) view; ScrollView. Delayscontenttouches = NO; break; }}< /c13>
|
* * Additional processing in IOS 8
123456789 |
At the place where the TableView is initializedFor(IdViewInchSelf.Subviews){ If([Nsstringfromclass([ViewClass])Isequaltostring:@ "Uitableviewcellscrollview"]){ If ([view iskindofclass:[ Uiscrollview class]) { span class= "n" >uiscrollview *scrollview = (uiscrollview *) view; scrollview. Delayscontenttouches = no; } break; }} /span>
|
UIButton on UITableViewCell