상당히 일반적인 질문이, 내가 몇 가지 답변을 가지고 끌어와 내가 거의 다입니다. I 누를 때 (이하 코드)에 의해, 화상을 생성하는 버튼을이있는 UIImage 터치를 감지하고
(numImages 제로로 부하 설정되고 생성 된 모든 이미지 태그 번호의 카운트 업으로서 사용된다)
UIImage *tmpImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%i.png", sender.tag]] retain];
UIImageView *myImage = [[UIImageView alloc] initWithImage:tmpImage];
numImages += 1;
myImage.userInteractionEnabled = YES;
myImage.tag = numImages;
myImage.opaque = YES;
[self.view addSubview:myImage];
[myImage release];
는 그때 감동 있는지 감지하는 touchesBegan 방법이있다. 내가해야 할 일은 새로 생성 된 이미지를 드래그 할 수있게하는 것이다. 거의 작동하지만 이미지를 드래그하면 이미지가 깜박입니다. 내가 클릭 한 이미지에 액세스 할 수 있지만 태그를 얻을 수는 있지만 멋지게 드래그 할 수는 없습니다.
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if (touch.view.tag > 0) {
touch.view.center = location;
}
NSLog(@"tag=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);
}
- (void) touchesMoved:(NSSet *)touches withEvent: (UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
각 이미지에 대한 태그 출력을 클릭하면 작동합니다. 그러나 끌고 갈 때, 그것은 깜박입니다 ... 어떤 생각입니까?
위의 코드는 http://www.iphoneexamples.com/에서이 게시 –
감사를 제공하지만,이 일을하는 동안 나는 그것을 피할 수있는 방법, 지터 효과는 무엇입니까? – itsaboutcode
고마워요! 매력처럼 작동 :) – soupdiver