이미지 뷰를 드래그하려고합니다. 그렇게하는 데 약간의 성공을 거두었지만, 내가 원하는만큼 행동하지는 않습니다. 나는 그것이 이미지 내부를 만져서 끌면 움직여야한다. 화면의 아무 곳이나 눌러서 드래그해도 움직입니다. 이 같은 코드를 기록한이미지 뷰 드래그
는 :
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//retrieve touch point
CGPoint pt= [[ touches anyObject] locationInView:[self.view.subviews objectAtIndex:0]];
startLocation = pt;
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint pt = [[touches anyObject] locationInView: [self.view.subviews objectAtIndex:0]];
CGRect frame = [[self.view.subviews objectAtIndex:0]frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[[self.view.subviews objectAtIndex:0] setFrame: frame];
}
왜'subviews'에 액세스? 이미지 뷰의 인스턴스를 선언 할 수 있습니다. 그리고 CGRectContainsPoint를 사용하여 이미지 뷰를 터치했는지 확인합니다. – Ilanchezhian
터치 할 때 터치 포인트가 이미지 뷰에 있는지 확인할 수 있습니다. – Bonny
이미지 뷰의 프레임이 전체 화면을 덮도록 설정되어 있습니까? –