简体   繁体   中英

Clip or mask 'touchable' area of a UITableViewCell within a flexible width UITableView

I have an iOS app with a UITableView that has flexible width, which allow me to automatically place scrollbar on the right hand side of my iPad, during orientation change.

However, my cell view has a non resizable background which is supposed to show the user what the touchable area is. However, if the user touch far outside the background, the gesture is intercepted as a didSelect event, because the table is covering the whole screen, and so does the table cell.

I am therefore looking for a way to parse user touch, see if it is outside the background, and accept it or not.

To complicate things, I am using UIStoryBoard.

UPDATE: just to complete the answer, of the two solutions suggested by lolcat, I have chosen to override the NSResponder method, because I have a UIStoryBoard in place with all the segues already drawn. By using the NSResponder I didn't change a line of code in my view controller.

I have done something like this by placing an invisible button over the cell where the touch should be intercepted. Create a function to respond as the selector to that button which will act like your didSelectRowAtIndexPath function normally would.

Otherwise you can subclass UITableViewCell and override touchesBegan (or touchesEnded - based on what you're looking for). This will allow you to see the exact point tapped within the cell. This method can be seen here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM