swiftについての質問です。
今回、CoreMotionフレームワークを用いて加速度センサーの値を取り出そうと以下のサイトのコードを書いてみたのですが、import CoreMotionの箇所で以下の警告文がでてインポートできません。
"File 'ViewController.swift is part of module 'CoreMotion';ignoring import'."
参考サイト:https://sites.google.com/a/gclue.jp/swift-docs/ni-yinki100-ios/5-coremotion/001-jia-su-dusensano-zhiwo-qu-de
ちなみにCoreMotion.frameworkはLinked Frameworks and Librariesから追加しました。
そして、そのコードを一応以下に記載しておきます。
ViewController.swift
1import UIKit 2import CoreMotion 3 4class ViewController: UIViewController { 5 6 var myMotionManager: CMMotionManager! 7 8 override func viewDidLoad() { 9 10 super.viewDidLoad() 11 12 // Labelを作成. 13 let myXLabel: UILabel = UILabel(frame: CGRectMake(0,0,200,50)) 14 myXLabel.backgroundColor = UIColor.blueColor() 15 myXLabel.layer.masksToBounds = true 16 myXLabel.layer.cornerRadius = 10.0 17 myXLabel.textColor = UIColor.whiteColor() 18 myXLabel.shadowColor = UIColor.grayColor() 19 myXLabel.textAlignment = NSTextAlignment.Center 20 myXLabel.layer.position = CGPoint(x: self.view.bounds.width/2,y: 200) 21 22 let myYLabel: UILabel = UILabel(frame: CGRectMake(0,0,200,50)) 23 myYLabel.backgroundColor = UIColor.orangeColor() 24 myYLabel.layer.masksToBounds = true 25 myYLabel.layer.cornerRadius = 10.0 26 myYLabel.textColor = UIColor.whiteColor() 27 myYLabel.shadowColor = UIColor.grayColor() 28 myYLabel.textAlignment = NSTextAlignment.Center 29 myYLabel.layer.position = CGPoint(x: self.view.bounds.width/2,y: 280) 30 31 let myZLabel: UILabel = UILabel(frame: CGRectMake(0,0,200,50)) 32 myZLabel.backgroundColor = UIColor.redColor() 33 myZLabel.layer.masksToBounds = true 34 myZLabel.layer.cornerRadius = 10.0 35 myZLabel.textColor = UIColor.whiteColor() 36 myZLabel.shadowColor = UIColor.grayColor() 37 myZLabel.textAlignment = NSTextAlignment.Center 38 myZLabel.layer.position = CGPoint(x: self.view.bounds.width/2,y: 360) 39 40 // Viewの背景色を青にする. 41 self.view.backgroundColor = UIColor.cyanColor() 42 43 // ViewにLabelを追加. 44 self.view.addSubview(myXLabel) 45 self.view.addSubview(myYLabel) 46 self.view.addSubview(myZLabel) 47 48 // MotionManagerを生成. 49 myMotionManager = CMMotionManager() 50 51 // 更新周期を設定. 52 myMotionManager.accelerometerUpdateInterval = 0.1 53 54 // 加速度の取得を開始. 55 myMotionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: {(accelerometerData:CMAccelerometerData!, error:NSError!) -> Void in 56 myXLabel.text = "x=\(accelerometerData.acceleration.x)" 57 myYLabel.text = "y=\(accelerometerData.acceleration.y)" 58 myZLabel.text = "z=\(accelerometerData.acceleration.z)" 59 }) 60 61 } 62 63}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/09 02:46 編集