我正在创建一个简单的鼓机。此功能控制播放的每个样本之间的时间(从而控制鼓机的节奏)。我需要用滑块来控制节奏,所以如果可能的话,我希望能用这个来控制‘持续时间到下一步’的值。然而,当我尝试这样做时,它告诉我“时间是NSDate的一部分”。
-(void)run
{
@autoreleasepool
{
// get current time
NSDate* time = [NSDate date];
// keeping going around the while loop if the sequencer is running
while (self.running)
{
// sleep until the next step is due
[NSThread sleepUntilDate:time];
// update step
int step = self.step + 1;
// wrap around if we reached NUMSTEPS
if (step >= NUMSTEPS)
step = 0;
// store
self.step = step;
// time duration until next step
time = [time dateByAddingTimeInterval:0.5];
}
// exit thread
[NSThread exit];
}
}这告诉我NSTimeInterval是一个不兼容的类型
// time duration until next step
time = [time dateByAddingTimeInterval: self.tempoControls];这里是声明滑块的地方
.m
- (IBAction)sliderMoved:(UISlider *)sender
{
AppDelegate* app = [[UIApplication sharedApplication] delegate];
if (sender == self.tempoSlider)
{
PAEControl* tempoControl = app.tempoControls[app.editIndex];
tempoControl.value = self.tempoSlider.value;
}
}.h
@interface DetailController : UIViewController
@property (weak, nonatomic) IBOutlet UISlider *tempoSlider;
- (IBAction)sliderMoved:(UISlider *)sender;如有任何帮助,我将不胜感激,提前谢谢。
发布于 2016-04-17 23:11:54
看起来self.tempoControls是PAEControl对象的数组。名为dateByAddingTimeInterval:的方法需要一个NSTimeInterval (也称为double)类型的参数。看起来您正在尝试传入此数组。
尝试更改此行-
time = [time dateByAddingTimeInterval: self.tempoControls];可能是这个-
PAEControl* tempoControl = self.tempoControls[self.editIndex];
time = [time dateByAddingTimeInterval: (NSTimeInterval)tempoControl.value];另一方面,如果这一切都在主线程上运行,请注意您正在阻塞它,并且UI将变得非常无响应。
https://stackoverflow.com/questions/36677882
复制相似问题