Note that there are some explanatory texts on larger screens.

plurals
  1. POMy touchesBegan wont trigger
    primarykey
    data
    text
    <p>Hi I have a problem I haven't been able to figure for a couple of days. I have a touchesBegan method that I want to use to tell when someone is tapping a UIImageView so it can move a different UIImageView up and down with NSTimers. For some reason my TouchesBegan wont work, i know that this is the issue because I tested with NSLogs and the results point to the method not being called. Here is my code, THANKS P.S. if there is a super quick fix and it makes me look dumb i'm sorry i've only developed for 6 days now.</p> <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self.view]; if (CGRectContainsPoint(flyImageButton.frame, pt)) { flying = YES; [playerFall invalidate]; playerFlyUp = [NSTimer scheduledTimerWithTimeInterval:.03 target:self selector:@selector(flyUp) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:playerFlyUp forMode:NSRunLoopCommonModes]; } } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (flying == YES) { flying = NO; [playerFlyUp invalidate]; [self startFallTimer]; } } </code></pre> <p>Here is my .h file for the person who asked...</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface GameViewController : UIViewController { IBOutlet UILabel *scoreLabel, *coinsLabel; IBOutlet UIImageView *flyImageButton, *playerImage, *flyingObject; IBOutlet UIScrollView *scroll; int score; int coins; BOOL flying; NSTimer *playerFlyUp, *playerFall, *scoreTimer, *coinsTimer; } @end </code></pre> <p>I Have also tried UITouch like so...</p> <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //CGPoint pt = [[touches anyObject] locationInView:self.view]; UITouch *touch = [[event allTouches]anyObject]; //if (CGRectContainsPoint(flyImageButton.frame, pt)) { if ([touch view] == flyImageButton) { flying = YES; [playerFall invalidate]; playerFlyUp = [NSTimer scheduledTimerWithTimeInterval:.03 target:self selector:@selector(flyUp) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:playerFlyUp forMode:NSRunLoopCommonModes]; } } </code></pre> <p>What is really confusing to me is how NSLog "Pos 1" never triggers, no matter where I touch...</p> <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //CGPoint pt = [[touches anyObject] locationInView:self.view]; UITouch *touch = [[event allTouches]anyObject]; CGPoint loc = [touch locationInView:self.view]; //This NSLog never displays leading me to think that my CGPoint isn't the issue... NSLog(@"Pos 1"); if (CGRectContainsPoint(flyImageButton.frame, loc)) { //if ([touch view] == flyImageButton) { NSLog(@"Pos 2"); flying = YES; [playerFall invalidate]; playerFlyUp = [NSTimer scheduledTimerWithTimeInterval:.03 target:self selector:@selector(flyUp) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:playerFlyUp forMode:NSRunLoopCommonModes]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload