【发布时间】:2011-08-19 11:17:52
【问题描述】:
我正在使用此代码在屏幕上显示随机图像。
- (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 中删除它们?为什么我用的是随机的,动画总是从左上角开始?
【问题讨论】:
标签: objective-c cocoa-touch uiview uiimageview uitouch