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