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

发布于 2024-11-08 19:06:31 字数 813 浏览 3 评论 0原文

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

任何建议都非常受欢迎。

I am stumped here as of right now, I wish to enact a UIView Animation on a finger press, by creating a UIView around where the finger is placed. Is this possible?

- (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];
}

Any suggestions are more than welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄人书 2024-11-15 19:06:31

这是由于您编写了以下行,

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

}

Its due to u written following line

[box removeFromSuperview];
    [box release];

This line u have to call after completion of box image animation.

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

}
遗忘曾经 2024-11-15 19:06:31

就像RRB所说,在动画完成后执行removeFromSuperView(我不确定他的代码会这样做)。我想它应该看起来像这样:

//initializations of everything here ..
[UIView animateWithDuration:1.0                  
 animations:^
 {
   //do animations here
 }
 completion:^(BOOL finished)
 {
    //do clean up here
 }]; 

Like RRB said, do the removeFromSuperView after completion of the animation (I'm not sure sure his code would). It should look like this, I think:

//initializations of everything here ..
[UIView animateWithDuration:1.0                  
 animations:^
 {
   //do animations here
 }
 completion:^(BOOL finished)
 {
    //do clean up here
 }]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文