2

我有一个关于UIPickerView. 我目前正在编写一个带有一个UIPickerView和一个按钮的应用程序,该按钮可以旋转UIPickerView.

这是我目前用于 IBAction 旋转的代码

-(IBAction)spin:(id)sender
{
    [pickerView selectRow: (arc4random() % [myArray count]) inComponent: 0 animated: YES];
}

它旋转得很好,但我希望旋转持续时间更长一点。我想实现类似于 Urbanspoon 的老虎机的东西。任何人都知道如何实现这一目标?

4

1 回答 1

0

您可以使用以下代码实现所需的行为:

- (IBAction)spin:(id)sender {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kMySpinDuration];
    NSInteger randomRow = arc4random() % [myArray count];
    [self.picker selectRow: randomRow inComponent:0 animated:NO];
    [UIView commitAnimations];
}

其中 kMySpinDuration 是您的自定义动画持续时间。

于 2016-03-07T22:06:07.013 回答