【问题标题】:Unable to call DCRoundSwitch UIControlEventTouchUpInside event无法调用 DCRoundSwitch UIControlEventTouchUpInside 事件
【发布时间】:2012-09-24 09:53:57
【问题描述】:

我使用 DCRoundSwitch 创建自定义开关,问题是我无法调用 UIControlEventTouchUpInside 事件,但只有 UIControlEventValueChanged 事件被调用。

以下是我在 viewdidload 中编写的代码:

self.swtchDailyReminder.on = YES;
self.swtchDailyReminder.onTintColor =[UIColor colorWithRed:47.0/255.0 green:160.0/255.0
blue:158.0/255.0 alpha:1.0];
[self.swtchDailyReminder addTarget:self action:@selector(switchDailyReminderToggled:)
forControlEvents:UIControlEventTouchUpInside];

提前致谢。

【问题讨论】:

    标签: objective-c ios custom-controls uiswitch


    【解决方案1】:

    UIControlEventTouchUpInside 消息是通过DCRoundSwitchtouchesEnded 方法发送的。因此,需要调用此方法才能让您的交换机接收消息以触发您的操作。这不会发生,因为touchesCancelled 是由UIGestureRecognizers 发送的——当他们识别出他们的手势时,他们会自动取消对其他视图的触摸。如果您在创建UIGestureRecognizers 并使用其cancelsTouchesInView 属性将其附加到交换机(在DCRoundSwitch 的设置方法中)时关闭此行为,这将允许touchesEnded 将其UIControlEventTouchUpInside 消息发送到您的交换机,以便触发您的操作。

    希望这会有所帮助。

    // 注意:如果您的目标动作要运行一些动画,您需要对DCRoundSwitch 进行一些进一步的更改,以防止它阻塞您的动画。更多详情请见this SO answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-21
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-03
      相关资源
      最近更新 更多