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

它是由于你写了以下行

[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 回答