###前提・実現したいこと
iPhoneの電子コンパスの情報を取得して、画像を回転させたいと思っています。
###発生している問題・エラーメッセージ
エラーメッセージはありません。
実機デバッグすると画像は表示されるだけでデバイスを動かしても全く回転しません。
問題点がわからないので教えて頂きたいです。
###該当のソースコード
import UIKit import CoreLocation class ViewController: UIViewController, CLLocationManagerDelegate { // UIImageViewを作成する. let myImageView = UIImageView(frame: CGRect(x:0, y:0, width:300, height:300)) var locationMgr : CLLocationManager // 初期化処理 required init(coder aDecoder: NSCoder) { locationMgr = CLLocationManager() super.init(coder: aDecoder)! } override func viewDidLoad() { super.viewDidLoad() // 表示する画像を設定する. let myImage = UIImage(named: "myarrow2.png") // 画像をUIImageViewに設定する. myImageView.image = myImage // 画像の表示する座標を指定する. myImageView.layer.position = CGPoint(x: self.view.bounds.width/2, y: 200.0) // UIImageViewをViewに追加する. self.view.addSubview(myImageView) locationMgr.delegate = self locationMgr.headingFilter = kCLHeadingFilterNone locationMgr.headingOrientation = CLDeviceOrientation.portrait locationMgr.startUpdatingHeading() } private func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { // 回転角度の計算 let rt = -CGFloat(2 * M_PI * newHeading.magneticHeading / 360.0) // 画像を回転させる myImageView.transform = CGAffineTransform(rotationAngle: rt) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
###補足情報(言語/FW/ツール等のバージョンなど)
Swift3.0/Xcode8.0/iOS10.0.2/MacOS10.11
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/26 09:48
2016/10/26 10:20
2016/10/26 10:21
2016/10/26 10:40