我有1个滑块的视图。我想把Sphero球拿在手里,所以当球向左或向右倾斜时,滑块向左或向右移动。
最好的示范项目是什么?
答案 0 :(得分:2)
你应该看看其中一个:
答案 1 :(得分:1)
我会使用https://github.com/orbotix/Sphero-iOS-SDK/tree/master/samples/SensorStreaming
在handleAsyncData内添加对滑块的引用:
- (void)handleAsyncData:(RKDeviceAsyncData *)asyncData
{
if ([asyncData isKindOfClass:[RKDeviceSensorsAsyncData class]]) {
packetCounter++;
if( packetCounter > (TOTAL_PACKET_COUNT-PACKET_COUNT_THRESHOLD)) {
[self sendSetDataStreamingCommand];
}
// Received sensor data, so display it to the user.
RKDeviceSensorsAsyncData *sensorsAsyncData = (RKDeviceSensorsAsyncData *)asyncData;
RKDeviceSensorsData *sensorsData = [sensorsAsyncData.dataFrames lastObject];
RKAccelerometerData *accelerometerData = sensorsData.accelerometerData;
RKAttitudeData *attitudeData = sensorsData.attitudeData;
// this Assumes your Slider has been hooked up in the Interface Builder
// With float values between 1.0 and 0.0
[MyAccelerometerSlider setFloatValue:accelerometerData.acceleration.x];
// You could also set it to the Roll value which is better for controller stuff
[MyOtherSlider setDoubleValue:attitudeData.roll];
}
}
只需将要监视的轴从x更改为y或z。您还可以使用Streaming示例中的其他流功能。即。海拔高度和四元数。
这是Sphero加速计传感器的图表: