我有一个动画,它连续在屏幕上运行。现在,当您触摸屏幕某个部分的动画时,我正试图获得警报。
目前我已经到了这样的地步,如果你触摸屏幕中间你会得到一个警报。
SelectedCellViewController.h
#import <Accounts/Accounts.h>
#import <QuartzCore/QuartzCore.h>
@interface SelectedCellViewController : UIViewController {
IBOutlet UIImageView *rocket;
}
@end
SelectedCellViewController.m
#import "SelectedCellViewController.h"
@interface SelectedCellViewController ()
@end
@implementation SelectedCellViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
}
return self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(imageSpawn:) withObject:nil afterDelay:3];
}
- (void) imageSpawn:(id) sender
{
UIImage* image = [UIImage imageNamed:@"ae"];
rocket = [[UIImageView alloc] initWithImage:image];
rocket.frame = CGRectMake(-25, 200, 25, 40);
[UIView animateWithDuration:5
delay:0.2f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^(){rocket.frame=CGRectMake(345, 200, 25, 40);}
completion:^(BOOL fin) {
}];
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ballTapped:)];
tapped.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tapped];
[self.view setUserInteractionEnabled:YES];
[self.view addSubview:rocket];
}
-(void)ballTapped:(UIGestureRecognizer *)gesture
{
// [rocket.layer removeAllAnimations];
NSLog(@"Tag = %d", gesture.view.tag);
CGPoint location = [gesture locationInView:gesture.view];
Rocket.frame = CGRectMake(location.x,location.y,25,40);
CGPoint location1 = [gesture locationInView:gesture.view];
CGRect rectToCompare = CGRectMake(10.0f, 200.0f, 200.0f, 42.0f);
if (CGRectContainsPoint(rectToCompare, location1)) {
//trigger an event.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tapped row!"
message:[NSString stringWithFormat:@"Shot"]
delegate:nil
cancelButtonTitle:@"Yes, I did!"
otherButtonTitles:nil];
[alert show];
}
}
- (void)viewDidUnload {
}
@end