我添加了一个 uiswitch 并希望通过手势将其移动到另一个位置。但 uipangesture 不适用于 uiswitch .. 下面是我的代码
UISwitch *swich = [[UISwitch alloc]initWithFrame:CGRectMake(20, 20, 40, 50)];
swich.userInteractionEnabled = YES;
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(switchdraged:)];
[swich addGestureRecognizer:gesture];
[self.view addSubview:swich];
函数switchdraged没有被调用..
下面是开关拖动功能
- (void)switchdraged:(UIPanGestureRecognizer *) gesture1
{
UISwitch *swich = (UISwitch *)gesture1.view;
CGPoint translation = [gesture1 translationInView:swich];
swich.center = CGPointMake(swich.center.x + translation.x,
swich.center.y + translation.y);
// reset translation
[gesture1 setTranslation:CGPointZero inView:swich];
}