- (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];
}
任何建议都非常受欢迎。
答案 0 :(得分: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];
}
答案 1 :(得分:0)
就像RRB说的那样,在动画完成后做removeFromSuperView
(我不确定他的代码会不会)。它应该看起来像这样,我想:
//initializations of everything here ..
[UIView animateWithDuration:1.0
animations:^
{
//do animations here
}
completion:^(BOOL finished)
{
//do clean up here
}];