0
我想创建一个折叠动画UISlider。基本上,滑块将缩略图的大小,直到它被触摸,在哪个点它会扩展到正在改变的全尺寸。值更改后,滑块松开后,滑块将折回原始大小(缩略图大小)。iOS - 折叠动画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
问题是,当你开始触摸,你已经开始与控制,这意味着它可以跟踪价值变动交互。如果您同时调整控件的大小,您可以看到这不是一个好主意。也可能以奇怪的方式行事。 – Daniel
返回值(特别是'self.tracking')可能是一个问题。我认为你可以通过改变一个子视图框架来实现更简单,更安全,否则布局将会被破坏。 –