29

画面全体でアニメーション化されている iPhone ImageView の現在の位置を見つけようとしています。

そのようにimageViewを作成してアニメーション化します

-(IBAction)button:(UIButton *)sender{
    UIImageView *myImageView =[[UIImageView alloc] initWithImage:
                                     [UIImage imageNamed:@"ball.png"]];    
    myImageView.frame = CGRectMake(0, self.view.frame.size.height/2, 40, 40);    
    [self.view addSubview:myImageView];
    [myArray addObject:myImageView];

    [UIView animateWithDuration:.5 
                          delay:0 
                options:(UIViewAnimationOptionAllowUserInteraction) // | something here?)
                     animations:^{
                         myImageView.frame = CGRectOffset(myImageView.frame, 500, 0);    
                     }
                     completion:^(BOOL finished){
                         [myArray removeObject:myImageView];
                         [myImageView removeFromSuperview];
                         [myImageView release];
                     }
     ];
}

次に、imageView の現在の CGPoint を検出するために、このメソッドを 60 秒ごとに呼び出します

-(void)findPoint{

    for (UIImageView *projectile in bullets) {        
         label.text = [NSString stringWithFormat:@"%f", projectile.center.x];
         label2.text = [NSString stringWithFormat:@"%f", projectile.center.y];
    }
}

ただし、これはアニメーションが終了するポイントのみを示します。画面全体でアニメーション化されている画像の現在の CGPoint を取得したいと考えています。これを行うために UIViewAnimationOptionAllowUserInteraction 以外に適用する必要があるオプションはありますか? そうでない場合、アニメーション imageView の現在の位置を取得するにはどうすればよいですか?

4

2 に答える 2

53

「現在表示されているレイヤーのバージョンに近いものを提供する」CALayer のプロパティである presentationLayer を使用できます。次のように使用してください。

CGRect projectileFrame = [[projectile.layer presentationLayer] frame];
于 2011-10-02T08:30:29.877 に答える