Ios 在重新选择的索引处设置动画不起作用
我在我的Ios 在重新选择的索引处设置动画不起作用,ios,objective-c,animation,core-plot,Ios,Objective C,Animation,Core Plot,我在我的xcode项目中使用饼图实现了corePlot。我在动画方面遇到了麻烦。选定切片后,径向偏移将随动画而更改。代码如下: - (void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)idx { if (self.selectedIndex == idx) { [self animateSelectedIndex:20 :0]; self.sele
xcode
项目中使用饼图实现了corePlot
。我在动画方面遇到了麻烦。选定切片后,径向偏移将随动画而更改。代码如下:
- (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时)清除
选择的索引
会立即将径向偏移量变为零。直到动画完成后才清除它。可以使用动画代理,或在偏移量达到零后在-setSliceOffset:
中清除它