当用户首次进入应用程序时,我想动画(闪烁)UISlider的拇指(以指示要点击的内容)。
我将UIImage设置为拇指:
[self.textNavigationSlider setThumbImage:thumbImage forState:UIControlStateNormal];
我可以以某种方式为它制作动画(也许只是将此UIImage的alpha更改为动画)?
PS(此播放按钮是UIImage)
答案 0 :(得分:1)
如果您想要一次,请按以下步骤操作。
答案 1 :(得分:1)
我不相信你可以为图像的alpha值设置动画,并且我们无法访问拇指的图像视图(如果有的话)来为其alpha设置动画。您可以做的一件事是将图像视图添加为滑块的子视图,并使其略大于拇指图像,并为其Alpha值设置动画(它将在拇指的图像后面,因此它将显示为脉动环)。在这个例子中,我在thumbRectForBounds:trackRect:value:中设置了图像视图的框架,并取消了touchesBegan中的动画,
@interface RDSlider ()
@property (strong, nonatomic) UIImageView *iv;
@end
@implementation RDSlider // subclass of UISlider
-(void)awakeFromNib {
self.minimumTrackTintColor = [UIColor colorWithRed:75/255.0 green:180/255.0 blue:150/255.0 alpha:1];
self.maximumTrackTintColor = [UIColor colorWithRed:50/255.0 green:120/255.0 blue:100/255.0 alpha:1];
[self setThumbImage:[self createThumbImage] forState:UIControlStateNormal];
self.iv = [UIImageView new];
self.iv.backgroundColor = [UIColor greenColor];
[self addSubview:self.iv];
}
-(void)didMoveToWindow {
[UIView animateWithDuration:.6 delay:0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionRepeat|UIViewAnimationOptionCurveEaseInOut animations:^{
self.iv.alpha = 0;
} completion:^(BOOL finished) {
[self.iv removeFromSuperview];
self.iv = nil;
}];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.iv.layer removeAllAnimations]; // calling this causes the animation's completion block to be executed
[super touchesBegan:touches withEvent:event];
}
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value {
CGRect thumbRect = [super thumbRectForBounds:bounds trackRect:rect value:value];
self.iv.frame = CGRectInset(thumbRect,-2,-2);
self.iv.layer.cornerRadius = self.iv.frame.size.width/2.0;
self.iv.layer.masksToBounds = YES;
return thumbRect;
}
-(UIImage *) createThumbImage {
UIBezierPath *border = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 28, 28)];
UIBezierPath *center = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(.5, .5, 27, 27)];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(border.bounds.size.width, border.bounds.size.height), NO, 0.0);
[self.minimumTrackTintColor setFill];
[border fill];
[[UIColor whiteColor] setFill];
[center fill];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
答案 2 :(得分:1)
您可以制作滑块的精确副本,除了没有拇指图像,并将其放在第一个之下。然后在理论上为整个第一个滑块的alpha设置动画,这应该给人一种只有动画拇指的印象;-)动画完成后,你可以删除第二个滑块。
答案 3 :(得分:0)
您可以访问UISlider object.subviews。通常(不保证)第三个元素(应该是.lastObject)是拇指图像的UIImageView。