0
我試圖通過我在.xib中的UISlider更改我的UIAcceleromter的updateInterval。我的NSLogs向我顯示了完美的值,但是當我移動滑塊時,加速度計的間隔不會增加。我不確定有什麼問題。通過UISlider更改UIAccelerometer的updateInterval
我很感激提供的任何幫助。這裏是我的代碼:
ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIAccelerometerDelegate> {
}
- (IBAction)sliderValueChanged:(UISlider *)slider;
@end
ViewController.m:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize XAxis, YAxis, delta;
float value;
- (void)viewWillAppear:(BOOL)animated
{
UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 1.0f * value;
NSLog(@"Value: %f",value);
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
NSLog(@"X: %g",acceleration.x);
NSLog(@"Y: %g",acceleration.y);
NSLog(@"Z: %g",acceleration.z);
}
- (IBAction) sliderValueChanged:(UISlider *)slider
{
value = slider.value;
NSLog(@"Value: %f",slider.value);
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
@end
我該如何去做它的財產?這是我唯一不瞭解的事情。 – klcjr89 2012-07-24 18:19:34
我想我明白了!非常感謝! – klcjr89 2012-07-24 20:11:21