我想创建一个折叠动画 UISlider。基本上,滑块将调整缩略图的大小,直到它被触摸时,它会在更改时扩展为全尺寸。更改值并放开滑块后,滑块将折叠回原始大小(缩略图的大小)。
我尝试使用 touchesBegan 和 touchesEnd 但这并没有让我走得太远。
到目前为止,我已经继承了 UISlider 并覆盖了 beginTrackingWithTouch 和 endTrackingWithTouch。这段代码完成了折叠效果(当然没有动画),但拇指滑块不再改变。关于如何最好地做到这一点的任何想法?
#import "CollapsingUISlider.h"
@implementation CollapsingUISlider
/*-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width * 4.0f, self.frame.size.height);
[super touchesBegan:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width * 0.25f, self.frame.size.height);
[super touchesEnded:touches withEvent:event];
}*/
-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, 400, self.frame.size.height);
return YES;
}
-(void)endTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent *)event {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, 20, self.frame.size.height);
}
-(BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, 400, self.frame.size.height);
return self.tracking;
}
@end