微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过动画Did Stop方法传递整数变量

如何解决通过动画Did Stop方法传递整数变量

| 我必须通过动画序列传递一个变量,但是我很难弄清楚如何添加它。当我尝试将yesNo的整数值添加到我的animationDidStop方法中时,无法正确传递它:
- (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];

}
    

解决方法

尝试使用:
- (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
因此不需要指针。     ,很抱歉回答我自己的问题,但是如果这对其他人有用的话,这里... 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]];

}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。