2
當我旋轉我的形象的看法:如何將double類型轉換爲CGAffineTransform?
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
imageView?.transform = newHeading.trueHeading
}
我得到以下錯誤:
Cannot assign value of type 'CLLocationDirection' (aka 'Double') to type 'CGAffineTransform'
如何轉換/分配呢?
UPDATE:
一切編譯好了,但是當我在模擬器中運行我的應用程序(我沒有任何iOS設備),我的ImageView的不是真北旋轉。
爲什麼?
import UIKit
import CoreLocation
class ViewController: UIViewController,CLLocationManagerDelegate {
var manager: CLLocationManager?
var imageView: UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager = CLLocationManager()
manager?.delegate = self;
manager?.desiredAccuracy = kCLLocationAccuracyBest
imageView = UIImageView(image:#imageLiteral(resourceName: "pointer"))
self.view.addSubview(imageView!)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
imageView?.transform = CGAffineTransform(rotationAngle: CGFloat(newHeading.trueHeading))
}
}
什麼是你想在這裏做什麼?你想旋轉圖像視圖嗎? – rmaddy
是@rmaddy我想旋轉我的圖像視圖當我旋轉設備 – BBann