1

私はアニメーションを持っており、それは画面全体に継続的に実行されます。画面の特定の部分でアニメーションに触れたときにアラートを取得しようとしています。

現在、画面の中央をタッチするとアラートが表示されるようになりました。

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];

ロケット.フレーム = CGRectMake(場所.x,場所.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 
4

1 に答える 1

1

アニメーションの途中でビュー属性の値を取得するには、ビュー レイヤーのpresentationLayer. ドキュメントに記載されているように:

このメソッドによって返されるレイヤー オブジェクトは、現在画面に表示されているレイヤーの近似値を提供します。アニメーションの進行中に、このオブジェクトを取得し、それを使用してそれらのアニメーションの現在の値を取得できます。

view.layer.presentationLayer.frameしたがって、 where viewis yourを使用UIImageViewして、画面上のアニメーション レイヤーの現在の位置を取得できます。これを使用して、フレームが検出したい境界内にあるかどうかをテストするのは簡単です。

于 2013-03-30T17:14:00.727 に答える