0

我想创建一个折叠动画 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
4

1 回答 1

0

我最终做了这样的事情:

 UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[platformView addGestureRecognizer:panRecognizer];

-(void)move:(id)sender {
[self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];

if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
    firstX = [[sender view] center].x;
    firstY = [[sender view] center].y;
}

translatedPoint = CGPointMake(firstX, firstY+translatedPoint.y);
[[sender view] setCenter:translatedPoint];
if (platformView.center.y < platformCenter.y - offset) {
    platformView.center = CGPointMake(platformCenter.x,platformCenter.y-offset);
    ((UIPanGestureRecognizer*)sender).enabled = NO;
} else if (platformView.center.y > platformCenter.y) {
    platformView.center = CGPointMake(platformCenter.x,platformCenter.y);
    ((UIPanGestureRecognizer*)sender).enabled = NO;
}
}
于 2013-07-02T17:27:36.347 回答