答案 0 :(得分:2)
我建议在发布问题之前阅读文档。根本不熟悉这个库,在30秒内,我下载了源代码,找到了文档,然后浏览,直到找到 - (void)flowCover:(FlowCoverView *)视图didSelect:(int)cover,看起来像是一个委托方法。
乍一看,看起来你并不想知道前面和中心是什么,只知道用户选择的东西(这可能很好地意味着“刚刚成为前线和中心的东西”)。测试一下,看看。
答案 1 :(得分:1)
您可以通过更改FlowCoverView.h中的委托协议轻松获取此通知,如下所示:
@protocol FlowCoverViewDelegate
- (int)flowCoverNumberImages:(FlowCoverView *)view;
- (UIImage *)flowCover:(FlowCoverView *)view cover:(int)cover;
- (void)flowCover:(FlowCoverView *)view didSelect:(int)cover;
- (void)flowCover:(FlowCoverView *)view highlighted:(int)cover; //<-- Added
@end
将FlowCoverView.m中的-[FlowCoverView driveAnimation]
方法替换为:
- (void)driveAnimation
{
double elapsed = CACurrentMediaTime() - startTime;
if (elapsed >= runDelta) [self endAnimation];
else [self updateAnimationAtTime:elapsed];
/*
* Change by Uppfinnarn <uppfinnarn@gmail.com>.
* This will give the Delegate a message every time the highlighted cover (eg. the one in the center) changes.
* Can be used to display subtitles for example.
*/
if (delegate) [delegate flowCover:self highlighted:(int)floor(offset + 0.01)]; // make sure .99 is 1
}
在某处创建一个UILabel并将其放在FlowCoverView的顶部(确保它的不透明是NO,这样它就不会在它后面创建一个黑盒子),然后监视-[flowCover:highlighted:]
以了解当前哪个封面中心并相应地更改文本。
请注意,只有在动画移动时,才会通知您第一次创建视图的时间。你必须自己弄清楚第一个标题。
此外,当用户用手指拖动时,这不会给你通知,只有当它“自由滑动”时才会发出通知。
编辑:
用这个替换你的-[FlowCoverView touchesMoved:withEvent:]
方法,以便在用户用手指拖动时获得回调:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect r = self.bounds;
UITouch *t = [touches anyObject];
CGPoint where = [t locationInView:self];
double pos = (where.x / r.size.width) * 10 - 5;
if (touchFlag) {
// determine if the user is dragging or not
int dx = fabs(where.x - startTouch.x);
int dy = fabs(where.y - startTouch.y);
if ((dx < 3) && (dy < 3)) return;
touchFlag = NO;
}
int max = [self numTiles]-1;
offset = startOff + (startPos - pos);
if (offset > max) offset = max;
if (offset < 0) offset = 0;
/*
* Change by Uppfinnarn <uppfinnarn@gmail.com>.
* Based on Ilkka Pirttimaa <ilkka.pirttimaa@gmail.com>'s solution for notifications.
* when the animation stops.
*
* This will give the Delegate a message every time the highlighted cover (eg. the one in the center) changes.
* Can be used to display subtitles for example.
*/
if(delegate) [delegate flowCover:self highlighted:(int)floor(offset + 0.01)];
[self draw];
double time = CACurrentMediaTime();
if (time - startTime > 0.2) {
startTime = time;
lastPos = pos;
}
}