0
이 코드를 사용하여 임의의 이미지를 화면에 표시합니다.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에서 어떻게 제거합니까? 그리고 랜덤을 사용하고 있는데도 왜 애니메이션은 항상 왼쪽 상단에서 시작합니까?
- (IBAction)clearClouds:(id)sender{
[[[self view] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
}
클라우드
는 항상 왼쪽 상단에서 시작되어보기에 추가 된 유일한 파단이clouds
를 있다고 가정