重新选择的索引的动画不起作用

时间:2015-05-04 02:33:41

标签: ios objective-c animation core-plot

我使用饼图在corePlot项目中实施了xcode。我在制作动画时遇到了麻烦。选择切片后,径向偏移会随动画而变化。这是代码:

- (void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)idx
{
    if (self.selectedIndex == idx)
    {
        [self animateSelectedIndex:20 :0];
        self.selectedIndex = -1;
    }
    else
    {
        self.selectedIndex = idx;
        [self animateSelectedIndex:0 :20];
    }
}

- (void)animateSelectedIndex:(CGFloat)from :(CGFloat)to
{
    [CPTAnimation animate:self
                 property:@"sliceOffset"
                     from:from
                       to:to
                 duration:0.25
           animationCurve:CPTAnimationCurveCubicInOut
                 delegate:nil];
}

- (CGFloat)radialOffsetForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx
{
    return  idx == self.selectedIndex ? sliceOffset : 0.0;
}

- (void)setSliceOffset:(CGFloat)newOffset
{
    if (newOffset != sliceOffset) {
        sliceOffset = newOffset;
        [self.graph reloadData];
    }
}

问题是,当切片重新选择时,切片的径向偏移变为0,但它没有动画为0.(当它从0变为20时,它会进行动画处理唯一的问题是当它从20变为0时

1 个答案:

答案 0 :(得分:0)

清除selectedIndex会立即将径向偏移驱动为零。在动画结束之前不要清除它。在偏移量达到零之后,您可以使用动画委托或在-setSliceOffset:中清除它。