iPhone - 在触摸位置使用 UIView 动画
我现在被难住了,我希望通过在手指放置的地方创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是由于您编写了以下行,
您必须在完成框图像动画后调用该行。
Its due to u written following line
This line u have to call after completion of box image animation.
就像RRB所说,在动画完成后执行
removeFromSuperView
(我不确定他的代码会这样做)。我想它应该看起来像这样: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: