Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
317
11
Hi all..

Here I am yet again with yet another problem.
I wanted to create a UIView to deal with all my input (swipes. shake) needs

but I create and add the view from a the main myAppDelegate window

Code:
[[self window] addSubview:myNewView];

I can get shakes to work.

Code:
- (BOOL)canBecomeFirstResponder {
	return YES;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if ( event.subtype == UIEventSubtypeMotionShake ) {
        NSLog(@"Shake!");
		functionText =(NSMutableString *) @" SHAKE !!! ";
		[self setNeedsDisplay];
    }
	
    if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
        [super motionEnded:motion withEvent:event];
    }
	
	
		
}

but gestures are a no go.

Code:
- (void)ViewDidAppear
{

	UISwipeGestureRecognizer *oneFingerSwipeLeft = 
  	[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeLeft:)] autorelease];
	[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
	[self  addGestureRecognizer:oneFingerSwipeLeft];
}

- (void)oneFingerSwipeLeft:(UISwipeGestureRecognizer *)recognizer 
{ 
	NSLog(@"Swipe Left");
	CGPoint point = [recognizer locationInView:self];
	NSLog(@"Swipe left - start location: %f,%f", point.x, point.y);
}

Zero error but I did have to trigger ViewDidAppear manually (I did try viewDidAppear nothing triggered) from Delegate.
long and short of the question:

Will gestures only work in a NSViewcontroller ? :(
or is there another way to get gestures to work in a UIView?

One thing might be I have a layer of buttons on the window (which is on top of the view) but don't start the swipe on any of them when I'm testing it.

*** Ok thinking (as I wrote) about this I add the UISwipeGestureRecognizer to the window and it worked !! I guess because it was the top layer.

But one thing comes to mind .. should I rejig my code to put all the buttons and shake on separate views working under a view controller and put next to nothing in the window myAppDelegate.. ??? is that better form?


thanks fir your help

Ian
 
But one thing comes to mind .. should I rejig my code to put all the buttons and shake on separate views working under a view controller and put next to nothing in the window myAppDelegate.. ??? is that better form?

I would say yes, re the view controller. That is the reason for view controller's existence.

Anything in your app delegate should be related to the application itself, not any particular view.
 
Hi all..

...gestures are a no go.
Code:
- (void)ViewDidAppear
{
	UISwipeGestureRecognizer *oneFingerSwipeLeft = ...

Try:
Code:
- (void)viewDidAppear:(BOOL)animated
{
       [super viewDidAppear:animated];
	UISwipeGestureRecognizer *oneFingerSwipeLeft = ...

It's case sensitive and you're missing a required parameter. If you're loading your view from a NIB, then you'll need to instead have:

Code:
- (void)awakeFromNib
{
	UISwipeGestureRecognizer *oneFingerSwipeLeft = ...
 
tried viewDidAppear.

tried.

Code:
- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated]; // <--------- Error code ------ see below 
        NSLog(@"**** appear da View ****");
}

but nothing triggered..

Is this because I'm (calling/creating) it from window / Delegate vs. a Controller ??

Getting
Code:
/Users/test/Coding/xcode/Archive - current project/EChallenge-2011-10-29/Classes/dealWithItGestureView.m:21:0 /Users/test/Coding/xcode/Archive - current project/EChallenge-2011-10-29/Classes/dealWithItGestureView.m:21: warning: 'UIView' may not respond to '-viewDidAppear:'

Think I might bite the bullet and rejig the app to lots of various UIView, a controller and a window. Although it seem like overkill for what I want.
which is a glorified solitaire game..

thanks
Ian

Ps. What's the best way to send commands from UIView to UIView?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.