我在自定义UISwitch DCRoundSwitch的选择器方法中完成了以下动画代码。
if ([[[App.remindersArray objectAtIndex:0] objectAtIndex:3]isEqualToString:@"YES"]){
[firstReminderOnOffButton setSelected:YES];
[swtchDailyReminder setOn:YES];
imgviewDailyReminder.image=[UIImage imageNamed:@"nDailyReminder_On_1.png"];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35];
[UIView setAnimationDidStopSelector:@selector(animateFadingIn)];
[UIView setAnimationDelegate:self];
imgviewDailyReminderAnimation.alpha = 1.0;
[UIView commitAnimations];
}
else
{
[firstReminderOnOffButton setSelected:NO];
[swtchDailyReminder setOn:NO];
imgviewDailyReminder.image=[UIImage imageNamed:@"xDailyReminder_OFF.png"];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35];
[UIView setAnimationDidStopSelector:@selector(animateFadingIn)];
[UIView setAnimationDelegate:self];
imgviewDailyReminderAnimation.alpha = 0.0;
[UIView commitAnimations];
}
问题是当从普通UISwitch调用上面的代码时动画正常工作,但是从DCRoundSwitch调用时不能正常工作。
还试图通过使用UIView块动画解决....但仍然面临问题。
请指导我。
答案 0 :(得分:1)
问题出在DCRoundSwitch's
动画块中。在CATransaction
的完成块中未创建setOn:animated:ignoreControlEvents:
,导致[UIView animateWithDuration...]
方法在响应交换机的值被更改时被调用时无法正常工作。
要解决问题,只需更改:
if (previousOn != on && !ignoreControlEvents)
[self sendActionsForControlEvents:UIControlEventValueChanged];
要:
if (previousOn != on && !ignoreControlEvents)
{
[CATransaction begin];
[CATransaction setDisableActions:NO];
[self sendActionsForControlEvents:UIControlEventValueChanged];
[CATransaction commit];
}
应该这样做
答案 1 :(得分:0)
我使用了以下代码。这是正常的。
请跟进此主题
https://github.com/domesticcatsoftware/DCRoundSwitch/issues/12
你可以直接去使用这个DCRoundSwitch的Class,在该类的dealloc方法中放入这行。
- (void)dealloc
{
[self.MyDCRoundSwitch removeTarget:nil
action:NULL
forControlEvents:UIControlEventAllEvents];
[super dealloc];
}