0
我需要实现自定义UISwitch,为此我使用RCSwitch类(感谢Ray Wenderlich和Robert Chin)。RCSwitch激活一次触摸两次
因此,我添加了RCSwitch类到我的项目,连接图形,它看起来不错,但!这并不好。检查了这一点:
验证码:
//@interface
@property (nonatomic, strong) RCSwitchOnOff *onSwitch;
//implementation
- (void)viewDidLoad
{
[super viewDidLoad];
self.onSwitch = [[RCSwitchOnOff alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 39.5, self.view.frame.size.height/2 - 150, 80, 35)];
[self.onSwitch addTarget:self action:@selector(switchSwitched:) forControlEvents:UIControlEventTouchUpInside];
// self.defaultSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 39.5, self.view.frame.size.height/2 - 150, 80, 35)];
// [self.defaultSwitch addTarget:self action:@selector(switchSwitched:) forControlEvents:UIControlEventTouchUpInside];
.
.
.
}
- (void)switchSwitched:(id)sender
{
NSLog(@"switch touched!");
}
原因这NSLog的
2013-03-15 09:56:54.575 Secret-Project[1190:c07] switch touched!
2013-03-15 09:56:54.576 Secret-Project[1190:c07] switch touched!
对于一个用户触摸方法switchSwitched火灾的两倍! 而当我取消defaultSwitch并评论switch时,正常的UISwitch只能启动switchSwitched方法一次。
这是什么?这里有人有同样的问题吗?
霍德你解决了吗?我不认为对图书馆最后一行的评论是解决方案,对吧? – Jan 2013-07-28 21:31:33
其实我评论了最后一行,但毕竟在最终版本我放弃使用RCSwitch,所以也许有另一种解决方案。顺便说一句:如果你评论最后一行开关仍然正常工作。 – lvp 2013-07-31 10:09:38