프로그래밍/Object-C
Object-C에서 touch event 처리방법
쿡지
2009. 6. 5. 16:49
728x90
반응형
터치이벤트의 좌표를 받아서 화면의 그림을 드래그 하거나 이동시킬수있도록 하는 소스입니다. 처음 터치가 시작되는 위치가 startLocation에 저장되고 그 후에 움직임에 따른 location에 적용해줍니다.
CGPoint startLocation;
CGPoint location;
// Handles the start of a touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Retrieve the touch point
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
}
// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:self];
location.x = pt.x - startLocation.x;
location.y = pt.y - startLocation.y;
}
CGPoint startLocation;
CGPoint location;
// Handles the start of a touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Retrieve the touch point
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
}
// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:self];
location.x = pt.x - startLocation.x;
location.y = pt.y - startLocation.y;
}
728x90
반응형