iOS 5.0 sendEvent called two [2] times - ios

I subclassed the UIWindow, but for some reason the - (void)sendEvent:(UIEvent *)event gets called 2 times for any interaction with the screen. Any ideas why would that happen?

For debugging purposes, subclass window (of app delegate) and override sendEvent: method
-(void) sendEvent:(UIEvent *)event
{
NSLog(#"%#",event);
[super sendEvent:event];
}
Most probably, you will notice the events responsible for TouchesBegan and TouchesEnded (for tapping). This can be tested by subclassing the View and overriding touch related methods.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"tocuhesBegan");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"touchesCancelled");
}
Also, try drag/swipe on the view to notice the change in count of events sent to view :)

sendEvent gets called for fingerDown and allFingersUp

Related

iPhone 6s not receiving any touches on UIButtons

My Application works on every device except some iPhone 6s. When user tries to tap on buttons nothing happens. I checked Buttons frames and everything is right but still nothing happens when user taps on buttons. I think this is something touch related. Any kind of help here will be appreciated. Thanks.
If you have used any UIButton Category and Overrides the Touch methods
then try adding:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
}

iOS delay touchUpInside button event

I have some custom animations in my UIButton subclass. I override some inner methods for starting and ending animation
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
//there is my start animation
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
//there is my end animation
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
//there is my end animation
}
There is almost all good. All my buttons make some actions on event UIControlEventTouchUpInside. And there is my problem. Methods touchesEnded and touchesCancelled are called only after my app handle UIControlEventTouchUpInside event. So animations in button looks not so nice like I want.
So question is: can I delay UIControlEventTouchUpInside event on some ms and firstly handle touchesEnded method of my button for smooth animation?

How to get the position of the current touch?

I'm building a game that basically the goal is to hold a button pressed for a long time.
The game starts with the "touchesBegan" call, and ends on "touchesEnded".
I have a issue that some very specific times this call, is not called. After a some search i figured out i'm not the only one with this problem :
https://discussions.apple.com/thread/1507669?tstart=0
There is a known problem that some times "touchesEnded" is not called.
So the work around i was thinking of doing, is setting a timer, and checking every once in a while, if there is a finger pressing, and where exactly on the screen.
Problem is, i know only about these methods:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
And nun of them serve me for this use.
Is there a way of getting the current touch on screen?
Thanks
touchesCancelled:withEvent:
When a touch begins, touchesBegan:withEvent: is called. After that, at some point in the future, either touchesEnded:withEvent: or touchesCancelled:withEvent: will be called! You can, e.g. create a method touchesEndedOrCancelled:withEvent: and call that method from both touchesEnded and touchesCancelled.
To get the current touches you need to keep track of them on your own. Just create a mutable set _allTouches
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[_allTouches unionSet:touches];
// ...
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[_allTouches minusSet:touches];
// ...
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_allTouches minusSet:touches];
// ...
}

why cant we detect a UITouch logic on UITableView, Objective C

I searched but not quite understand why we cant detect a UITouch on UITableView. What I am having right now is :a view controller with a table view located in its view. Please look at the picture below for your reference
In implementation class, I am enabling breakpoint for each UITouch methods which are
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
I notice that, these breakpoints are invoked if and only if you touch outside of the table view ( orange area )
I do not get it. I thought UITableView is subclass of UIScrollView which is subclass of UIView which is subclass of UIResponder. It means UITouch should be invoked. (correct me if I am wrong )
All comments are welcomed and appreciated here.
Rather than tampering with the table view, use a gesture recognizer. You can act as the delegate to ensure that all interactions work concurrently and enable and disable the gestures if / as required.
You can detect touches method in the UITableView by subclassing it as this:
I Test it and it print "Test" successfully
//TestTable.h
#import <UIKit/UIKit.h>
#interface TestTable : UITableView
#end
//TestTable.m
#import "TestTable.h"
#implementation TestTable
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog("Test");
}
Tables utilize scroll views to handle panning, which use a pan gesture recognizer. Why not just tap into that?
CGPoint location = [self.tableView.panGestureRecognizer locationInView:self.tableView];
If you wish to detect the touches on UITableView, create a subclass of tableview and add implement UIResponder method, canBecomeFirstResponder.
#interface MyTableView: UITableView
#end
#implementation: MyTableView
- (BOOL) canBecomeFirstResponder{
return YES;
}
// then implement all other touch related methods, remember to call super in these methods
// such that it correctly forwards the events to other responders
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
}
#end

iPhone - Detecting touches and canceling them?

I am dtecting touches on my UIView.
Is some situations I want to be abel to cancel touches so that touchesEnded won't get called. But doesn't matter what touchesEnded will always get called?
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (SOMETHING_SPECIAL)
{
[super touchesCancelled:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//I don't want it to get here if touches were canceled how can i do this?
}
- In my touchesEnded how can I determine whether touches were canceled or not?
TouchesEnded will always get called wherever your touches where canceled or not, so I would suggest instead having that exact:
if (SOMETHING_SPECIAL)
{
}
In your:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
To get the touchesCancelled event, implement this method from UIResponder.
touchesCancelled:withEvent:.

Resources