【发布时间】:2012-04-30 12:31:35
【问题描述】:
在我的 iPhone 应用程序中,我想玩触摸事件。这里我的要求如图:
我在Button 1 的touch drag Exit 事件上创建Button 2。这是代码
-(IBAction)addView:(id)sender{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag=count;
count++;
[button addTarget:self action:@selector(imageTouch:withEvent:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:self action:@selector(imageTouchCancel:withEvent:) forControlEvents:UIControlEventTouchUpInside];
button.frame=CGRectMake(shape1.frame.origin.x-30,shape1.frame.origin.y-40, 100, 100);
[button setImage:[UIImage imageNamed:imgname] forState:UIControlStateNormal];
[button addSubview:close];
[baseview addSubview:button];
}
在这里,我能够成功创建按钮 2,但问题是我无法在单点触摸事件中拖动和移动按钮 2,这意味着在按钮 1 上向外拖动时,它正在创建按钮 2,但要移动按钮 2,我必须将我的手指从屏幕上移开,然后在下一次触摸按钮 2 时,我可以移动按钮 2。
我的问题是,如何创建 button2 并在单次触摸循环中将其在屏幕上移动?
【问题讨论】:
-
我认为您需要使用
Touch方法并检测您正在触摸的对象。如果是 button2,那么您必须开始移动它,这会调用 touchesMoved。让我们玩!如果您需要更多帮助,请告诉我。
标签: iphone objective-c uibutton uitouch