Xcode 删除触摸事件图像?
我正在使用此代码在屏幕上显示随机图像。
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
UIImageView *cloud = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"spit.png"]];
cloud.center = CGPointMake(random() % 250, random() % 400); //Random place
[cloud setAlpha:1];
[self.view addSubview:cloud];
[cloud release];
cloud.frame = CGRectMake(0, 0, 300, 300);
[UIView beginAnimations: @"cloddy" context: nil];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseIn];
// Size when done
cloud.frame = CGRectMake(0, 0, 75, 75);
cloud.center = location;
[UIView commitAnimations];
}
触摸几次后,屏幕会变得有点满。如何在另一个 IBAction 中删除它们?为什么即使我使用随机,动画总是从左上角开始?
I'm using this code to display random images on the screen.
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
UIImageView *cloud = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"spit.png"]];
cloud.center = CGPointMake(random() % 250, random() % 400); //Random place
[cloud setAlpha:1];
[self.view addSubview:cloud];
[cloud release];
cloud.frame = CGRectMake(0, 0, 300, 300);
[UIView beginAnimations: @"cloddy" context: nil];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseIn];
// Size when done
cloud.frame = CGRectMake(0, 0, 75, 75);
cloud.center = location;
[UIView commitAnimations];
}
after a couple of touches the screen gets kinda full. How do I remove them inside another IBAction? And why does the animation always start in the upper left corner even though I'm using random?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设已添加到视图中的唯一子视图是
clouds
,云始终从左上角开始,因为这一行:
cloud.frame = CGRectMake(0, 0, 300, 300);
将其原点重置为 0,0。将cloud.center = CGPointMake(random() % 250, random() % 400);
移到您设置云框架的行下方,您应该已准备就绪。Assuming that the only subviews that have been added to your view are
clouds
,The cloud is always starting at the upper left because this line:
cloud.frame = CGRectMake(0, 0, 300, 300);
resets its origin to 0,0. Movecloud.center = CGPointMake(random() % 250, random() % 400);
below the line where you set the cloud's frame and you should be all set.