通过动画传递整数变量已停止方法

时间:2011-04-14 16:39:49

标签: iphone xcode animation

我必须通过动画序列传递一个变量,但是我无法弄清楚如何添加它。当我尝试将它添加到animationDidStop方法时,yesNo的整数值没有正确传递:

- (void) animateStart:(NSInteger *)yesNo {

    // AT THIS NSLOG POINT THE VALUE OF yesNO VARIABLE CHECKS OK:
    NSLog(@"animateStart yesNo: %i",yesNo);

    [UIView beginAnimations:@"startMove" context:NULL];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationDelegate:self];

    // HERE IS WHERE I TRY TO PASS THE yesNO VARIABLE:
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:yesNo:)];
    . . .

    [UIView commitAnimations];

}

// I TRY TO ADD THE yesNO VARIABLE HERE:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context yesNo:(NSInteger *)yesNo {

    // BUT THE NSLOG SHOWS THE WRONG VALUE (ALWAYS int 2)
    NSLog(@"animationDidStop yesNo: %i",yesNo);

    [self nextMethod:(NSInteger *)yesNo];

}

2 个答案:

答案 0 :(得分:1)

尝试使用:

- (void) animateStart:(NSInteger)yesNo

NSInteger只是int的一个typedef:

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif

所以没有必要指针。

答案 1 :(得分:0)

为回答我自己的问题而道歉,但如果这对其他任何人都有用,那么...... setAnimationDidStopSelector方法的animationID变量传递beginAnimations方法的NSString animationID,该方法是一个完全任意的值。因此,为了传递我的整数参数,我利用了这个暴露的参数,并将我的整数参数转换为NSString,并使用下面的代码返回:

- (void) animateStart:(NSInteger)yesNo {

    // cast the integer to a string:
    [UIView beginAnimations:[NSString stringWithFormat: @"%i",yesNo] context:NULL];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationDelegate:self];

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:yesNo:)];
    . . .

    [UIView commitAnimations];

}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
// cast the string back to an integer:
    [self nextMethod:(NSInteger)[animationID intValue]];

}