Comments (12)
This as a problem with the gesture recognizers detecting taps gobbling presses on cell views.
I've gotten around this problem by modifying the GMGridView's -gestureRecognizer:shouldRecieveTouch: to return false for either the tap or long-press gestures when the touched view is a subclass of UIControl or the descendent of one.
from gmgridview.
@mwyman Thank you very much for your reply. Do I have to use the gesture recognizer's view property and check if it's an UIControl class? Could you provide a simple snippet to reach the goal? Thank you.
from gmgridview.
I figured out a way to do it. For the sake of completeness I post the code I'm using. Maybe someone could be interested in.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if(gestureRecognizer == _tapGesture) {
UIView* touchedView = [touch view];
if([touchedView isKindOfClass:[UIButton class]]) {
return NO;
}
}
return YES;
}
from gmgridview.
That should work in most cases. However, you should also test against the _sortingLongPressGesture, and you may want to check whether the touched view is a descendent of a UIButton (actually, I'd generalize to UIControl).
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ( gestureRecognizer == _tapGesture || gestureRecognizer == _sortingLongPressGesture ) {
if ( [touch.view isDescendantOfView:self] ) {
// Test if the touched view is a subview of a control
for ( UIView *view = touch.view ; view != self ; view = view.superview )
if ( [view isKindOfClass:[UIControl class]] )
return NO;
}
}
return YES;
}
from gmgridview.
mwyman, nice solution!
from gmgridview.
Hey flexaddicted, I've tried adding a UIButton as a subview of my custom view but I can't get it to appear. Any idea what's missing?
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
view.backgroundColor = [UIColor greenColor];
view.layer.masksToBounds = NO;
view.layer.cornerRadius = 15;
UIButton *plainButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[plainButton setImage:[UIImage imageNamed:@"Itsy1.jpg"] forState:UIControlStateNormal];
[plainButton setFrame:CGRectMake(0, 0, 50, 50)];
[plainButton setTitle:@"Button" forState:UIControlStateNormal];
[view addSubview:plainButton];
[view bringSubviewToFront:plainButton];
cell.contentView = view;
from gmgridview.
flexaddicted, how did you go about knowing which position in the grid view was being clicked?
from gmgridview.
Do I have to modify your source code to add a button? If I use a XIB, do I also have to modify the grid source code? Thanks.
from gmgridview.
@DigiCub Seems ok to me. I don't know what the problem could be.
@mrevoir Could you explain what do you mean?
@Ricardo1980 You need to create a view with its button and add it as the contentView of the cell. Yes, you have to modify the code also with a xib.
from gmgridview.
@flexaddicted In thinking about how to better describe my question it struck me to look at how cell deletion currently works so I'll do that as well, but I am wondering how to determine which cell in the grid contained the button that was clicked. I can see that the button is receiving the event because my selector is invoked, but I don't know which of the buttons in the grid was clicked.
from gmgridview.
One method would be to use setTag: on your buttons when you get the cell in GMGridView:cellForItemAtIndex:, setting it to the index of the cell. Note that you will need to do this every time you recycle a cell, not just when you create the buttons.
from gmgridview.
Thanks! I would love to see this merged on the master though.
from gmgridview.
Related Issues (20)
- How can items drag in both the directions Left to Right and Right to Left ?
- GMGridView reloadData does not refresh view
- Archives has does not contain a single–bundle application or contains multiple products
- iOS 7 Horizontal strategy content size HOT 2
- No document about how to use this control
- if cell width is quite different, grid will show wrong cell when rotating
- ios 5.1 and lower issue HOT 1
- Grid cell want to draw from top HOT 1
- scrollToObjectAtIndex is not working properly when paging is enabled HOT 1
- memory problem - not released/reclaimed HOT 1
- another mem issue
- GMGrid Cell Alignment Issue
- Image stuck on screen
- Sort Help required!
- gridview.edit=yes,how to use sortingdelegate?
- index = -2147483648
- Maybe you can join a group function
- Button not working in subview GMGridviewCell
- Image link in README.md is broken
- animation repeat count doesn't work in GMGridViewCell
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmgridview.