2012-09-25 126 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]; 
}