/ / Arrastre el objeto específico - iphone, sdk

Arrastre el objeto específico - iphone, sdk

Tengo un problema con arrastrar objetos en sdk de iPhone, mi salida de UIImageView es roja y no sé por qué el arrastre no funciona. pero cuando elimino la línea If mi código funciona bien, aquí está el código:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


UITouch *touch = [[event allTouches]anyObject];

if ([touch view] == red) {
CGPoint location = [touch locationInView:self.view];
red.center = location;

}
}


- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

[self touchesBegan:touches withEvent:event];
}

Respuestas

1 para la respuesta № 1

Cuando sobrescribe los toques de una sub clase de UIView, solo los toques entregados a esa UIView se manejan allí.

Para sus subvistas, debe establecer UserInteractionEnabled en TRUE. Y luego crea una subclase para tus subvistas a través de la cual puedes delegar el manejo táctil a tu SuperView.

Si eso suena complejo, solo usa - (UIView *) hitTest: (CGPoint) punto con evento: (UIEvent *) evento


0 para la respuesta № 2

Hola, lo hice con el código a continuación. Tengo que arrastrar imageEnd de forma horizontal y vertical específica, así que los ato como a continuación.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView: touch.view];
location.x=510.0;
[imgEndPoint setUserInteractionEnabled:TRUE];

if ([touch view] == imgEndPoint) {
if (location.y < 710.0 && location.y > 75.0) {//image move between this coordinate
imgEndPoint.center = location;
}
}
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];

if ([touch view] == imgEndPoint) {

CGPoint location = [touch locationInView: self.view];
location.x=510.0;
if (location.y < 710.0 && location.y > 75.0) {
imgEndPoint.center = location;
[self getPixcel];
}
[imgEndPoint setUserInteractionEnabled:TRUE];
}
}