问题描述
我已经在自定义UISwitch DCRoundSwitch的选择器方法中完成了以下动画代码。
I have done following code for animation inside a selector method of custom 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];
}
问题是在调用上述代码时动画可以正常工作
The problem is animation is working properly when above code is called from normal UISwitch,but not working when called from DCRoundSwitch.
也尝试通过使用UIView块动画来解决....但仍然面临问题。
Also tried to resolve by using UIView block animation....but still facing the problem.
请指导我。
推荐答案
问题出在 DCRoundSwitch的
动画块。在 setOn:animated:ignoreControlEvents:
的完成代码块中未创建 CATransaction
,导致产生 [响应更改开关的值而调用时,UIView animateWithDuration ...]
方法无法正常工作。
The issue is in DCRoundSwitch's
animation block. No CATransaction
is created in the completion block of setOn:animated:ignoreControlEvents:
resulting in [UIView animateWithDuration...]
methods not working properly when called in response to the switch's value being changed.
要解决该问题,只需更改:
To solve the problem, just change:
if (previousOn != on && !ignoreControlEvents)
[self sendActionsForControlEvents:UIControlEventValueChanged];
收件人:
if (previousOn != on && !ignoreControlEvents)
{
[CATransaction begin];
[CATransaction setDisableActions:NO];
[self sendActionsForControlEvents:UIControlEventValueChanged];
[CATransaction commit];
}
应该这样做
这篇关于与DCRoundSwitch一起使用时,UIView动画不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!