旋转拨号器就像动画一样

时间:2013-05-07 04:34:28

标签: ios iphone uiviewanimation

我正在使用MHRotaryKnob来制作像动画一样的旋转拨号。我用它来制作旧的电话拨号盘。!image
目前它只是显示动画,当我拨打它刚刚回来的动画片。即使第一个圆圈从较低甚至没有检测到触摸,触摸也在那里工作,没有圆圈拨号。下面我发布我正在使用的代码。

 - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
 {
CGPoint point = [touch locationInView:self];

if (self.interactionStyle == MHRotaryKnobInteractionStyleRotating)
{
    // If the touch is too close to the center, we can't calculate a decent
    // angle and the knob becomes too jumpy.
    if ([self squaredDistanceToCenter:point] < MinDistanceSquared)
        return NO;

    // Calculate starting angle between touch and center of control.
    _angle = [self angleBetweenCenterAndPoint:point];
}
else
{
    _touchOrigin = point;
    _angle = [self angleForValue:self.value];
}

self.highlighted = YES;
[self showHighlighedKnobImage];
_canReset = NO;

return YES;
}

- (BOOL)handleTouch:(UITouch *)touch
{
if (touch.tapCount > 1 && self.resetsToDefault && _canReset)
{
    [self setValue:self.defaultValue animated:YES];
    return NO;
}

CGPoint point = [touch locationInView:self];

if (self.interactionStyle == MHRotaryKnobInteractionStyleRotating)
{
    if ([self squaredDistanceToCenter:point] < MinDistanceSquared)
        return NO;

    // Calculate how much the angle has changed since the last event.
    float newAngle = [self angleBetweenCenterAndPoint:point];
    float delta = newAngle - _angle;
    _angle = newAngle;

    // We don't want the knob to jump from minimum to maximum or vice versa
    // so disallow huge changes.
    if (fabsf(delta) > 45.0f)
        return NO;

    self.value += (self.maximumValue - self.minimumValue) * delta / (MaxAngle*2.0f);

    // Note that the above is equivalent to:
    //self.value += [self valueForAngle:newAngle] - [self valueForAngle:angle];
}
else
{
    self.value = [self valueForPosition:point];
}

return YES;
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
if ([self handleTouch:touch] && self.continuous)
    [self sendActionsForControlEvents:UIControlEventValueChanged];

return YES;
}

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
self.highlighted = NO;
[self showNormalKnobImage];

// You can only reset the knob's position if you immediately stop dragging
// the knob after double-tapping it, i.e. when tracking ends.
_canReset = YES;

[self handleTouch:touch];
[self sendActionsForControlEvents:UIControlEventValueChanged];

[self setValue:self.defaultValue animated:YES];


}

我正在努力实现选择了可以检测到的拨号圈,并且只能使用圈子拨打不在圈子外面。在此先感谢,任何形式的帮助表示赞赏。

1 个答案:

答案 0 :(得分:6)

稍微调整一下,这就是你要找的东西:

enter image description here

链接:https://github.com/eliotfowler/EFCircularSlider