iOS9, ipodtouch, Xcode7, Objective-C の初心者です。
特殊ローラーに ipodtouch を固定させ、傾斜を測定しています。
iPodtouh と この特殊ローラーの取り付けが完全(平行)ではないため、補正を行おうと思い、下図のように、alert 画面を使おうとしているのですが、2549行でコンパイルエラーが発生しています。
どなたか、改善策、アドバイス、ご教示頂けたら幸いです。
よろしくお願い致します。
頂いたアドバイスを元に、下記のように修正し、希望の機能を実現できました。
// ボタン押下時に Alert-1 を表示する - (IBAction)Button_comp:(UIButton *)sender { // 補正変数の初期化 angle_comp_1 =0; angle_comp_2 =0; angle_comp =0; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"補正(ステップ1/2)" message:@"補正しますか?" preferredStyle:UIAlertControllerStyleAlert]; // addActionした順に左から右にボタンが配置される [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // 「いいえ」ボタンが押された時の処理 [self cancelButtonPushed]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // 「はい」ボタンが押された時の処理 [self otherButtonPushed]; }]]; // 画面に表示します [self presentViewController:alertController animated:YES completion:nil]; } // アラートの「はい」ボタン押下処理 - (void)otherButtonPushed { // 定期的に実行するハンドラを設定 CMAccelerometerHandler handler = ^(CMAccelerometerData *angle_data, NSError *error){ [self animation:angle_data]; }; // 加速度センサーの利用を開始 [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]withHandler:handler]; CMAccelerometerData *angle_data = motionManager.accelerometerData; xac = angle_data.acceleration.x; // X 軸: 加速度G yac = angle_data.acceleration.y; // Y 軸: 加速度G angle_comp_1 = atan2(yac, xac) * - 180.0 / M_PI; // 傾斜角を小数点以下1桁の実数表示 self.Incl_Label.text = [NSString stringWithFormat:@"%4.1f", angle]; self.black.transform = CGAffineTransformMakeRotation(M_PI * angle / 180); [self alert_2]; } // アラートの「いいえ」ボタン押下処理 - (void)cancelButtonPushed { NSLog(@"いいえ!"); } - (void)alert_2{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"補正(ステップ2/2)" message:@"180度、水平反転してください。" preferredStyle:UIAlertControllerStyleAlert]; // addActionした順に左から右にボタンが配置される [alertController addAction:[UIAlertAction actionWithTitle:@"キャンセル" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // 「いいえ」ボタンが押された時の処理 [self cancelButtonPushed]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // 「はい」ボタンが押された時の処理 [self otherButtonPushed_2]; }]]; // 画面に表示します [self presentViewController:alertController animated:YES completion:nil]; } // アラートの「はい」ボタン押下処理 - (void)otherButtonPushed_2 { // 傾斜角を小数点以下1桁の実数表示 self.Incl_Label.text = [NSString stringWithFormat:@"%4.1f", angle]; self.black.transform = CGAffineTransformMakeRotation(M_PI * angle / 180); CMAccelerometerData *angle_data = motionManager.accelerometerData; xac = angle_data.acceleration.x; // X 軸: 加速度G yac = angle_data.acceleration.y; // Y 軸: 加速度G angle_comp_2 = atan2(yac, xac) * - 180.0 / M_PI; angle_comp = (angle_comp_1 + angle_comp_2)/2 ; self.comp_value.text = [NSString stringWithFormat:@"%4.1f", angle_comp]; // 角度計測を停止する [motionManager stopAccelerometerUpdates]; //angle_ar[] の初期化 int i; for (i=0; i <500; i++) {angle_ar[i] = 0; } // angle_disp[] 初期化 for (i=0; i<10; i++) { angle_disp[i] = 0;} // jcount の 初期化 jcount =0; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/08 21:27 編集
2016/06/09 00:13 編集
2016/06/11 08:19