Iphone 拖动特定对象
我在iPhone sdk中拖动对象时遇到问题,我的UIImageView插座是红色的,我不知道为什么拖动不起作用!但是当删除if行时,我的代码工作正常,下面是代码:Iphone 拖动特定对象,iphone,sdk,Iphone,Sdk,我在iPhone sdk中拖动对象时遇到问题,我的UIImageView插座是红色的,我不知道为什么拖动不起作用!但是当删除if行时,我的代码工作正常,下面是代码: - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches]anyObject]; if ([touch view] == red) { CGPoint l
- (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];
}
当覆盖UIView子类的touchesbeent时,只有传递到该UIView的触摸才会在那里处理 对于其子视图,需要将UserInteractionEnabled设置为TRUE。然后为子视图创建一个子类,通过该子类可以将触摸处理委托回SuperView 如果听起来很复杂,就使用
-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event当覆盖UIView子类的touchesBegind时,只有传递到该UIView的触摸才会在那里处理 对于其子视图,需要将UserInteractionEnabled设置为TRUE。然后为子视图创建一个子类,通过该子类可以将触摸处理委托回SuperView 如果听起来很复杂,就使用
-(UIView*)hitTest:(CGPoint)pointwithevent:(UIEvent*)event嗨,我是用下面的代码做的。我必须以特定的水平和垂直方式拖动imageEnd,所以我将它们绑定如下
-(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];
}
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint location=[touch locationInView:touch.view];
位置x=510.0;
[imgEndPoint setUserInteractionEnabled:TRUE];
如果([触摸视图]==imgEndPoint){
如果(location.y<710.0&&location.y>75.0){//图像在此坐标之间移动
imgEndPoint.center=位置;
}
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
如果([触摸视图]==imgEndPoint){
CGPoint location=[触摸位置视图:self.view];
位置x=510.0;
如果(位置y<710.0和位置y>75.0){
imgEndPoint.center=位置;
[self-getPixcel];
}
[imgEndPoint setUserInteractionEnabled:TRUE];
}
}
嗨,我是用下面的代码完成的。我必须以特定的水平和垂直方式拖动imageEnd,所以我将它们绑定如下
-(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];
}
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint location=[touch locationInView:touch.view];
位置x=510.0;
[imgEndPoint setUserInteractionEnabled:TRUE];
如果([触摸视图]==imgEndPoint){
如果(location.y<710.0&&location.y>75.0){//图像在此坐标之间移动
imgEndPoint.center=位置;
}
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
如果([触摸视图]==imgEndPoint){
CGPoint location=[触摸位置视图:self.view];
位置x=510.0;
如果(位置y<710.0和位置y>75.0){
imgEndPoint.center=位置;
[self-getPixcel];
}
[imgEndPoint setUserInteractionEnabled:TRUE];
}
}
您必须用cgpoint在“touchesMoved”上写下对象的位置您必须用cgpoint在“touchesMoved”上写下对象的位置谢谢,momeks rights,我想在屏幕上拖动这个物体是的。。我只是在回答你的问题,你只想在视图为(红色)的情况下进行此操作。谢谢你,momeks rights,我想在屏幕上拖动这个物体是的。。我只是在回答你的问题,你只想在视图为(红色)的情况下才这样做