Handle shake gesture within SKScene - cocoa-touch

I am experimenting with SpriteKite and it is handling touch events perfectly.
How can I implement a shake event? I assume I am failing the set the first responder correctly within the scene/when the scene is presented.
code within SKScene that is never called.
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake ) {
[self shakeEvent];
}
}
Thank you in advance

You may post a notification from the ViewController and add an observer to the SKScene.

Related

Interactive touch display

I'm looking to intercept all touch events on a parent UIView and display where the user touches but still bubble those touch events to children views i.e.. UIButtons, UITableViewCell, etc. so those children interact via their default manner.
I have no issues displaying touch events interactively on UIView using basic delegate methods:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
}
My issue at this point is bubbling these events to next responder when UIView contains other interactive children views such as UIButtons. touchesBegan: is never fired on parent view when tapping a button so I'm not able to display something "pretty" to user when taps buttons.
Is there a better way other than creating category for UIButton, UITableViewCell? Thanks
Here is an example of what I'm looking to do anytime user touches the screen... (notice the white circle when user touches buttons):
https://m1.behance.net/rendition/modules/154366385/disp/9532a948c71e28ffda2219600c05ffd9.gif
You can do it by creating a subclass of UIView.
The view should be on the top of the view hierarchy and its size should be full of the screen.
All touch events will be sent to this view. If you return NO in the pointInside:widthEvent: method, the touch event will be sent to the lower objects.
#implementation MyView
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// show bubble here
return NO; // send touch events to lower layer objects.
}

Global UIView touch notifications

I am looking for a way to detect if the UIWindow is touched at all, anywhere, in any view. Then I would like to dispatch a notification that a controller will respond to.
I am using this to make a time out (i.e. logout after inactivity)
Is there a notification I can subscribe to? this would be my preferred interaction. I don't want to have to implement my logic in every single view so categories could also work.
Perhaps there is an API that I am missing.
You could always subclass UIWindow and override the sendEvent: method
- (void)sendEvent:(UIEvent *)event;
{
[super sendEvent:event];
if (UIEventTypeTouches == event.type) {
NSLog(#"Touched");
}
}

UIGestureRecognizer or touchesBegan not responding

I have a normal app. Yes this will not work anywhere in it. If I place this in a ViewController, it will not work, if I place this in a UIView subclass, likewise, it refuses to work. What am I doing wrong?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"Please Work");
}
Make sure the view has userInteractionEnabled=YES. If a parent view has userInteractionEnabled=NO, the touches will be lost too. If that doesn't help, post code.

Affecting UIViewController from a child UIView

My question might sound rather strange, but still I didn't find any reference and I really need help.
so my point is, I have a ViewController which has a collection of UIViews, to be specific a subclass of UIView with
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
overridden
from this event i want to load a specific data (according on the UIView touched) on the UIViewController's child UIWebView
Is there a way to address parent ViewControllers children from the UIView that receives the action
Or am I looking into a completely wrong direction.
Any hel will be greatly appreciated, thanks in advance.
You can use delegate for example:
#protocol someProtocol
- (void)recivedTouch:(UITouch *)touch fromUIView:(UIView *)uiView;
in you view:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[self.delegate recivedTouch:touch fromUIView:self];
}
View controller implemed method from delegate:
- (void)recivedTouch:(UITouch *)touch fromUIView:(UIView *)uiView
{
if (uiView == self.someView)
{
// do some stuff with uiWebView
}
}
try to look at it differently. Your touchesBegan shouldn't do anything which is not connected with the view. Your view is just a UI component, it shouldn't control application flow (data loading). That's the job of the view controller.
Look how UIButton is implemented. The button does not do anything when clicked. The controller has to tell it "this is the method that should be called when the user clicks you"
There are two ways how to tell the view what it should do for a specific action - creating a delegate or passing a selector that should be called.
Consider also extending UIControl, which has most of the actions already implemented.
Alternatively use NSNotificationCenter: Send and receive messages through NSNotificationCenter in Objective-C?
Send a message from your view, hook the message from your controller. Notificationas can get a bit messy though, the delegate is probably a cleaner solution

Capture Touch Event on UITableViewCell and after enter didSelectRowAdTindePath method

I want to personalize my UITableView changing background when user tap on a specific cell.
I've a dedicated ViewController for each cell and if I implement touchesBegan method in this viewController i can change my cell background without any problem. The problem is that the method "didSelectRowAtIndexPath" of the UITableView is no longer called. How can I call it manually? I am in another viewController and I have no access to that method. or how can propagate to the touch tableView?
Thanks a lot
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//do your operations
//send it to super class
[super touchesBegan:touch withEvent:event];
}
[super touchesBegan:touch withEvent:event];
Are you sending your action to super class? If not then add this line.