3

私は今のところ困惑しています。指が置かれている場所の周りに UIView を作成することにより、指を押すと UIView アニメーションを制定したいと考えています。これは可能ですか?

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch * touch = [touches anyObject];
    CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
    NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y);
    //CGRect touchFrame = CGRectMake(pos.x, pos.y, 100, 100);
    UIView *box = [[UIView alloc] initWithFrame:CGRectMake(pos.x, pos.y, 100, 100)];
    NSLog(@"%f", box.frame.origin.x);
    [self.view addSubview:box];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:110 forView:box cache:NO];
    [UIView commitAnimations];
    [box removeFromSuperview];
    [box release];
}

どんな提案でも大歓迎です。

4

2 に答える 2

3

その原因は、次の行に書かれた u によるものです

[box removeFromSuperview];
    [box release];

この行は、ボックス イメージ アニメーションの完了後に呼び出す必要があります。

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{

    UITouch * touch = [touches anyObject];

    CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];

    UIView *box = [[UIView alloc] initWithFrame:CGRectMake(pos.x, pos.y, 100, 100)];

    [self.view addSubview:box];

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationTransition:110 forView:box cache:NO];

    [UIView commitAnimations];

[self performSelector:@selector(releaseBoxImge:) withObject:box afterDelay:1.0];

}


-(void)releaseBoxImge:(UIView *)boxImage
{

[boxImage removeFromSuperview];

    [boxImage release];

}
于 2011-05-20T09:17:36.087 に答える
0

RRB が言ったようremoveFromSuperViewに、アニメーションの完了後に実行します (彼のコードがそうするかどうかはわかりません)。次のようになるはずです。

//initializations of everything here ..
[UIView animateWithDuration:1.0                  
 animations:^
 {
   //do animations here
 }
 completion:^(BOOL finished)
 {
    //do clean up here
 }]; 
于 2011-05-20T09:35:50.980 に答える