2012-09-25 87 views
0

我在自定义UISwitch DCRoundSwitch的选择器方法内完成了以下动画代码。与DCRoundSwitch一起使用时UIView动画不起作用

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块动画....但仍然面临问题的解决。

请指导我。

回答

1

问题出在DCRoundSwitch's动画块。在setOn:animated:ignoreControlEvents:的完成块中创建了CATransaction,导致[UIView animateWithDuration...]方法在响应切换值被更改而调用时无法正常工作。

为了解决这个问题,只是改变:

if (previousOn != on && !ignoreControlEvents) 
[self sendActionsForControlEvents:UIControlEventValueChanged]; 

要:

if (previousOn != on && !ignoreControlEvents) 
{ 
[CATransaction begin]; 
[CATransaction setDisableActions:NO]; 
[self sendActionsForControlEvents:UIControlEventValueChanged]; 
[CATransaction commit]; 
} 

应该这样做

0

我已经使用这个下面的代码。哪些工作正常。

请跟进这个线程

https://github.com/domesticcatsoftware/DCRoundSwitch/issues/12

U可以随便去对正使用此DCRoundSwitch类,在把这个行类的dealloc方法。

- (void)dealloc 
{ 
     [self.MyDCRoundSwitch removeTarget:nil 
         action:NULL 
         forControlEvents:UIControlEventAllEvents]; 
     [super dealloc]; 
}