如何重复调用一个方法(加载...)具有定时动画过渡 [英] How to repeatedly call a method (reload...) with a timer to animate a transition
问题描述
我实施 corePlot
在我的 X code
项目。我想爆炸饼图与动画的片。下面是我使用的方法:
I implemented corePlot
in my xcode
project. I'm trying to "explode" a slice of the pie chart with animation. Here is the method I'm using:
- (void)radialOffsetForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx
{
if (myIndex == idx) {
return 20;
}
return 0;
}
我有一个叫 [饼图reloadRadialOffset]另一种方法。
例如:
- (void)thisMethod {
[pieChart reloadRadialOffset];
}
我怎样才能动画 reloadRadialOffsets
?
推荐答案
我只是说一个例子,在剧情画廊的示例应用程序简单饼图的试玩。我加入两个属性到控制器以保持选定的切片的索引和所需偏移值。由于偏移量为 CGFloat的
它使用的Core Animation动画轻松或 CPTAnimation
。
I just added an example to the "Simple Pie Chart" demo in the Plot Gallery example app. I added two properties to the controller to hold the index of the selected slice and the desired offset value. Since the offset is a CGFloat
it is easily animated using Core Animation or CPTAnimation
.
将指数 NSNotFound
来表示没有片应该被选中。如果你想同时突出多个切片,你也可以使用数组或设置索引。
Set the index to NSNotFound
to indicate that no slice should be selected. You could also use an array or set of indices if you want to highlight more than one slice at a time.
self.offsetIndex = NSNotFound;
触发动画,以抵消片:
Trigger the animation to offset the slice:
self.offsetIndex = idx;
[CPTAnimation animate:self
property:@"sliceOffset"
from:0.0
to:35.0
duration:0.5
animationCurve:CPTAnimationCurveCubicOut
delegate:nil];
剧情需要的数据源的径向偏移方式:
The plot datasource needs the radial offset method:
-(CGFloat)radialOffsetForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
{
return index == self.offsetIndex ? self.sliceOffset : 0.0;
}
的 sliceOffset
属性需要自定义设置器,触发剧情更新动画时的偏移量:
The sliceOffset
property needs a custom setter to trigger the plot to update the offsets during the animation:
-(void)setSliceOffset:(CGFloat)newOffset
{
if ( newOffset != sliceOffset ) {
sliceOffset = newOffset;
[self.graphs[0] reloadData];
}
}
这篇关于如何重复调用一个方法(加载...)具有定时动画过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!