UIGestureRecognizer blocking buttons in table cell views - iphone

I am using a custom UIGestureRecognizer on a UITableView.
As soon as I add the GestureRecognizer to the view, the buttons inside my table cells stop working (although changing the visible state to pressed, no action is being called).
And I am using [self setCancelsTouchesInView:NO]; and no recognizer chaining or what-so-ever.
Any ideas anyone?
Best regards,
Alex

It is possible that you are running into an issue with delaysTouchesEnded. Setting it to NO may fix your problem. Have a look at the docs.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html

Related

How to manage such animation in UITableView or with any other control?

i want to implement delete row with animation like this video.
Now deleting of row is easy task now i have question regarding how to manage animation like above video with UITable or any other control.
i refer some instance method. for tableview.
But in this, i am not getting how to manage animation like move row on touch in tableview.
Any suggestion appreciated.
Thanks
The animation would need to be a custom implementation. I would recommend having a subview on the UITableViewCell (the subview would be the red, the table view cell's background would be the black), and place a UIPanGestureRecognizer on the subview. You'd then need to move the subview as the user pans (in the gesture recognizer's method that is triggered), and do the math to know when the row should be deleted. Then you would just use the native iOS delete row method:
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
I found such cool custom control based on UITableView which provide exact animation i actually required.
You can found code here.

Alternative to UIScrollVIew

I have a quick question. I am trying to implement an application where the user can navigate between the screens via swipe gestures. So I am using gesture recognisers to push and pop views, the problem with that is that I don't want the transition animation to apply to the entire screen as there are certain similar components and it looks weird.
I considered using a scroll view, however I don't want to load all the controllers at the same time.
Any suggestions?
I'd suggest looking into UIGestureRecognizer and setting the UIScrollView property delaysContentTouches to NO to prevent the scroll view from consuming touch events before your gesture recognizer has the change to process the input, if you'd prefer that approach.
Don't forget that UIGestureRecognizer offers you quite a lot of information when the gesture fires.
I would suggest using a scroll view and load only the visible controller. You can then look for this delegate method, and load the other controller lazily
- (void)scrollViewDidScroll:(UIScrollView *)scrollView

UITableViewCell Swipe for Drawer

This is really more of a curiosity than a hard coding question.
Both Facebook and Twitter both have a feature where swiping a UITableViewCell animates the cell off the side to reveal a drawer with more controls underneath. How is something like that accomplished?
Here is a great open-source method for doing exactly this, based on the behavior of the Twitter app:
https://github.com/thermogl/TISwipeableTableView
This is a problem I have tried a couple of different solutions to. I really liked the behavior of Mailbox (mailboxapp.com). So I set out to achieve this. In the end I ended up with what I believe is a very simple solution: use a UIScrollView inside your cell. I have blog post that discusses and a sample app that demonstrates this behavior.
2 ways to detect swipt action
look at the willTransitionToState: method of UITableViewCell.
this method will be invoked when you swipe at the cell.
Custom swipe detection in a TableViewCell
and then you can change your cell view easily.
You could just implement -tableView:willBeginEditingRowAtIndexPath: in your table view delegate.
From the doc,
This method is called when the user swipes horizontally across a row; ... This method gives the delegate an opportunity to adjust the application's user interface to editing mode.
As a UITableViewCell is just a UIView, you can use this fact to basically do anything you like with it.
To solve your problem, I'd attach a UISwipeGestureRecognizer to detect the swipe and then animate the view to a different state.
For example, you could create a custom cell that has it's content view laying above the "actions view". Whenever there is a swipe, you use a UIView animation to move the content view aside and show the action view with a couple of buttons instead. In a custom UITableViewCell you could add a delegate protocol to have the pressed action and the cell being sent to the delegate, i.e. your controller. There you'd trigger what ever there is to trigger and then transition the cell out of the state.

Touch events not working on UIViews inside UIScrollView

I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. If I take the views out of the scroll view then it works.
I have enabled userInteraction on the views but it's still not working!
This must be possible and I'd be really grateful if someone could point me in the right direction!
Thanks,
Mike
Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller.
I have overcome this issue by overriding the loadView method of the view controller, and setting the view's instance variable to a simple UIView subclass which passes on the touches.
Check what you are returning in scrollview delegate method view for scrollin in scroll view.
As mahboudz mentioned - check if you have any custom handler for touch event. If not, please have one. Its far more relief to do whatever you want to do with your view. Check out Apples sample app from scrollViewSuite. They have tapDetectingImageView delegate. I used the same in my app it worked great! Hope this helps!
You may find this post useful. It's an example of a pretty clean way of intercepting events.
Have touch handlers for view for which you want to receive touch events and that will work.

Deselect UIButton on touch down outside

I have a UIButton that selects itself on UIControlEventTouchUpInside. It deselects itself on UIControlEventTouchUpOutside. I also want it to deselect itself when there is a touch down outside of the button. Is there a good way to do this without subclassing UIWindow and overriding -hitTest:withEvent:?
EDIT: I just found this question, which confirms my fear that there isn't a really clean way to do this.
This is not how buttons are supposed to work. They cannot be active if there is no touch active inside them. What are you really trying to implement? Maybe a UIBUtton is not the best choice here.
You can do this with your UIViewController by implementing the touchesBegan/Moved/Ended methods. If they detect a touch outside of the button, set its state back to normal. Take a look at Event Handling.
I solved this, and released the source. I didn't have to subclass UIWindow, but I did need to override -hitTest:withEvent:.