###前提・実現したいこと
textviewに加速度値のデータを少数3桁までだけ表示させたいのですが、うまくいきません
コンパイルは通るしクリーンしてもエラーが消えずどこをどう直していいかわかりません
###発生している問題・エラーメッセージ
acceleration CMAcceleration
self Mytest5.ViewController 0x000000010350d640
UIKit.UIViewController UIViewController
motionManager CMMotionManager 0x000005a10248d4cd
dataX [Double]
dataY [Double]
dataZ [Double]
accelX UILabel! 0x000005a10248d4cd
accelY UILabel! 0x000005a10248d4cd
accelZ UILabel! 0x000005a10248d4cd
TextView UITextView! 0x000005a10248d4cd
###該当のソースコード
Swift4
1import UIKit 2import CoreMotion 3 4class ViewController: UIViewController { 5 6 let motionManager = CMMotionManager() 7 var dataX:[Double] = [] 8 var dataY:[Double] = [] 9 var dataZ:[Double] = [] 10 11 @IBOutlet weak var accelX: UILabel! 12 @IBOutlet weak var accelY: UILabel! 13 @IBOutlet weak var accelZ: UILabel! 14 @IBOutlet weak var TextView: UITextView! 15 16 override func viewDidLoad() { 17 super.viewDidLoad() 18 if motionManager.isAccelerometerAvailable { 19 motionManager.accelerometerUpdateInterval = 0.2 20 21 motionManager.startAccelerometerUpdates( 22 to: OperationQueue.current!, 23 withHandler: {(accelData: CMAccelerometerData?, errorOC: Error?) in 24 self.outputAccelData(acceleration: accelData!.acceleration) 25 }) 26 27 } 28 } 29 func outputAccelData(acceleration: CMAcceleration){ 30 accelX.text = String(format: "x = %.4f", acceleration.x) 31 accelY.text = String(format: "y = %.4f", acceleration.y) 32 accelZ.text = String(format: "z = %.4f", acceleration.z) 33 34 dataX.append(acceleration.x) 35 dataY.append(acceleration.y) 36 dataZ.append(acceleration.z) 37 38 TextView.text = String(format: "%.3f %.3f %.3f \n",dataX,dataY,dataZ) 39 40 if ((acceleration.x >= 1.0)||(acceleration.x <= -1.0)) { 41 accelX.textColor = UIColor.red } 42 else if((acceleration.x <= 1.0)||(acceleration.x >= -1.0)) { 43 accelX.textColor = UIColor.black } 44 if((acceleration.y >= 1.0)||(acceleration.y <= -1.0)) { 45 accelY.textColor = UIColor.red } 46 else if((acceleration.y <= 1.0)||(acceleration.y >= -1.0)) { 47 accelY.textColor = UIColor.black } 48 if((acceleration.z >= 1.0)||(acceleration.z <= -1.0)) { 49 accelZ.textColor = UIColor.red } 50 else if((acceleration.z <= 1.0)||(acceleration.z >= -1.0)) { 51 accelZ.textColor = UIColor.black } 52 53 } 54 func stopAccelerometer(){ 55 if (motionManager.isAccelerometerActive) { 56 motionManager.stopAccelerometerUpdates() 57 } 58 } 59 override func didReceiveMemoryWarning() { 60 super.didReceiveMemoryWarning() 61 } 62 63}
###試したこと
ビルド前にクリーンしてみた
###補足情報(言語/FW/ツール等のバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/20 05:52
2017/11/20 06:10
2017/11/21 03:11
2017/11/21 03:47 編集
2017/11/21 12:25
2017/11/22 01:36
2017/11/22 06:44
2017/11/22 06:50
2017/11/23 00:52
2017/11/24 01:42
2017/11/24 07:24
2017/11/24 07:46
2017/11/24 12:55
2017/11/26 05:42
2017/11/26 05:43