gpt4 book ai didi

iPhone - 在触摸位置使用 UIView 动画

转载 作者:行者123 更新时间:2023-12-03 19:45:07 24 4
gpt4 key购买 nike

我现在被难住了,我希望通过在手指放置的地方创建一个 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];
}

欢迎任何建议。

最佳答案

这是由于你写了以下行

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

}

关于iPhone - 在触摸位置使用 UIView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6069752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com