在我的 iPhone 应用程序中,我想玩触摸事件。这里我的要求如图:
我Button 2
正在touch drag Exit
创建Button 1
. 这是代码
-(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 并在单次触摸循环中将其移动到屏幕上?