在重新选择的索引处设置动画不起作用
Animate at re-selected index not working
我在 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 时)
清除 selectedIndex
立即将径向偏移驱动为零。在动画结束之前不要清除它。您可以使用动画委托或在偏移量达到零后在 -setSliceOffset:
中清除它。
我在 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 时)
清除 selectedIndex
立即将径向偏移驱动为零。在动画结束之前不要清除它。您可以使用动画委托或在偏移量达到零后在 -setSliceOffset:
中清除它。