###前提・実現したいこと
iOSで加速度を取得し前回の値より大きく値が変わった回数を記録したいのです。
z軸の現在の加速度をdouble z;一つ前のをdouble zz;で宣言しています。
処理としてはif文でこの二つの差が一定値を超えるとint i;をプラス1して数を数えようとしています。
エラーの原因がわからず相談させてもらいます。
###発生している問題・エラーメッセージ
if文に入るまではいいのですがそこでなぜか毎回braek pointとなってしまいます。
###該当のソースコード
ViewController.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIAccelerometerDelegate> { UILabel* _label; int i; double zz; NSString* _orientation; } @property (weak, nonatomic) IBOutlet UILabel *xLabel; @property (weak, nonatomic) IBOutlet UILabel *yLabel; @property (weak, nonatomic) IBOutlet UILabel *zLabel; @property (weak, nonatomic) IBOutlet UILabel *bureki; @end
ViewController.m
#import "ViewController.h" #import <AudioToolbox/AudioServices.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //加速度センサーを定義 UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer]; //更新間隔を設定 accelerometer.updateInterval = 0.5; //デリゲートを selfに指定 accelerometer.delegate = self; } - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { //X軸の傾き度合いをラベルに表示 self.xLabel.text = [NSString stringWithFormat:@"x=%f", acceleration.x]; //Y軸の傾き度合いをラベルに表示 self.yLabel.text = [NSString stringWithFormat:@"y=%f", acceleration.y]; //Z軸の傾き度合いをラベルに表示 self.zLabel.text = [NSString stringWithFormat:@"z=%f", acceleration.z]; double z =acceleration.z; if(z - zz > 0.1) { i++; AudioServicesPlaySystemSound(1000); } self.bureki.text = [NSString stringWithFormat:@"%d",i]; zz =acceleration.z; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
###試したこと
if文の中身を全てコメントアウトして実行してみてもbreak pointになってしまったのでif文自体がダメみたいです。
###補足情報(言語/FW/ツール等のバージョンなど)
Xcode 7.3
iOS 9.3
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。