ios7中_块变量的使用

ios7中_块变量的使用,ios7,Ios7,我使用此代码为块中的变量赋值,我使用的是ios7 xcode5,它对我不起作用 _Block NSString *temp=Nil; [UIView animateWithDuration:0.7f delay:0.03f usingSpringWithDamping:30.0f initialSpringVelocity:30.0f options:UIViewAnimationOptionCurveLinear animations:^{ [vwBottomMain

我使用此代码为块中的变量赋值,我使用的是ios7 xcode5,它对我不起作用

_Block NSString *temp=Nil;    
[UIView animateWithDuration:0.7f delay:0.03f usingSpringWithDamping:30.0f initialSpringVelocity:30.0f options:UIViewAnimationOptionCurveLinear animations:^{
        [vwBottomMain setFrame:CGRectMake(0.0f, vwBottomMain.frame.origin.y-39, vwBottomMain.frame.size.width,vwBottomMain.frame.size.height)];
    } completion:^(BOOL finished) {
       temp=@"test";
    }];

虽然您没有显示此方法的其余部分,但最可能的问题是您的完成处理程序是异步的,但您希望立即得到结果

试着运行下面的代码,看看事情发生的顺序。它应该证明分配发生在测试之后

__block NSString *temp = nil;
[UIView animateWithDuration:0.7f delay:0.03f usingSpringWithDamping:30.0f initialSpringVelocity:30.0f options:UIViewAnimationOptionCurveLinear animations:^{
    NSLog(@"Animation section");
} completion:^(BOOL finished) {
    NSLog(@"Completion handler");
    temp = @"test";
}];
NSLog(@"String test %@", temp);