(a)如何制作删除线的动画?我尝试了以下但没有工作。
-(void)strikeThrough
{
NSNumber *strikeSize = [NSNumber numberWithInt:1];
NSDictionary *strikeThroughAttribute = [NSDictionary dictionaryWithObject:strikeSize forKey:NSStrikethroughStyleAttributeName];
NSAttributedString* strikeThroughText = [[NSAttributedString alloc] initWithString:_label.text attributes:strikeThroughAttribute];
_label.attributedText = nil;
[UIView animateWithDuration:2.0
animations:^{ _label.attributedText = strikeThroughText; }
completion:^(BOOL finished){ }];
}
(b)此外,删除线的样式与字体不匹配。例如,我使用粉笔字体,但是打击线看起来不像粉笔。怎么处理呢?
非常感谢你的帮助。
答案 0 :(得分:0)
拥有动画的一种方法是使用CATransition
NSNumber *strikeSize = [NSNumber numberWithInt:1];
NSDictionary *strikeThroughAttribute = [NSDictionary dictionaryWithObject:strikeSize forKey:NSStrikethroughStyleAttributeName];
NSAttributedString* strikeThroughText = [[NSAttributedString alloc] initWithString:self.mylabel.text attributes:strikeThroughAttribute];
self.mylabel.attributedText = nil;
CATransition *transition = [CATransition new];
transition.delegate = self;
transition.type = kCATransitionFromLeft;
transition.duration = 2.0f;
self.mylabel.attributedText = strikeThroughText;
[self.mylabel.layer addAnimation:transition forKey:@"transition"];
和完成块
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
//Check for CATransition here
}
第二点检查here。该链接简要介绍了其他方法来处理您希望打击的样子,您无法更改它的字体。
希望这有帮助。