简体   繁体   English

Swift 2.2中的iOS UIView.animatewithDuration?

[英]iOS UIView.animatewithDuration in Swift 2.2?

It's a flyover animation using UIMapKit and basically animation begins with camera angle changing and after that spin around the object. 这是一个使用UIMapKit的跨接动画,基本上动画是从更改相机角度开始,然后围绕对象旋转。 I got error, and I don't know what's wrong. 我出错了,我不知道怎么了。 Please help. 请帮忙。

" Pitch is the viewing angle of the camera, measured in degrees. A value of 0 results in a camera pointed straight down at the map. Angles greater than 0 result in a camera that is pitched toward the horizon by the specified number of degrees. If the map type is satellite or hybrid, the pitch value is clamped to 0. 俯仰角是摄像机的视角,以度为单位。值为0时,会使摄像机指向地图的正下方。大于0的角度将使摄像机向地平线倾斜指定的度数。如果地图类型是卫星地图或混合地图,则音调值将固定为0。

The value in this property may be clamped to a maximum value to maintain map readability. 可将此属性中的值限制为最大值,以保持地图的可读性。 There is no fixed maximum value, though, because the actual maximum value is dependent on the current altitude of the camera." 但是,没有固定的最大值,因为实际最大值取决于摄像机的当前高度。”

Now, the problem is, according to code below, I initialize the UIMapView pitch value to 0. Down below, override func, when it's time for animation, I change the value to 65, so I expect the camera angle(pitch) would change, but when I run in the simulator, camera is still pointed straight down at the map. 现在,问题是,根据下面的代码,我将UIMapView俯仰值初始化为0。下面,覆盖func,当它是动画时间时,我将该值更改为65,因此我希望摄影机的角度(俯仰)会改变,但是当我在模拟器中运行时,相机仍会直接指向地图。 But the spin animation is working, because the heading between pitched camera and rotated camera has changed. 但是旋转动画是有效的,因为俯仰摄影机和旋转摄影机之间的航向已更改。

I don't know what's wrong with my pitch setting. 我不知道我的音高设置有什么问题。 Did I miss something? 我错过了什么? Should I add altitude property? 我应该添加海拔属性吗? Still try to figure that out. 仍然设法弄清楚。

https://developer.apple.com/reference/mapkit/mkmapcamera https://developer.apple.com/reference/mapkit/mkmapcamera

import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    let distance: CLLocationDistance = 700
    let pitch: CGFloat = 65
    let heading = 90.0
    var camera = MKMapCamera()
    let coordinate = CLLocationCoordinate2D(latitude: 40.7484405,
                                            longitude: -73.9856644)
    @IBOutlet weak var mapView: MKMapView!


    override func viewDidLoad() {
        super.viewDidLoad()
        mapView.mapType = .SatelliteFlyover

        camera = = MKMapCamera(lookingAtCenterCoordinate: coordinate,
                             fromDistance: distance,
                             pitch: 0,
                             heading: 0)
        self.mapView.camera = camera
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {
        let pitchedCamera = MKMapCamera(lookingAtCenterCoordinate: coordinate, fromDistance: distance, pitch: pitch, heading: 0)
        let rotatedCamera = MKMapCamera(lookingAtCenterCoordinate: coordinate, fromDistance: distance, pitch: pitch, heading: 180)

        UIView.animateWithDuration(5.0, animations: {
            self.mapView.camera = pitchedCamera

            }, completion: {
                (Completed: Bool) -> Void in

                UIView.animateWithDuration(25.0, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {
                    self.mapView.camera = rotatedCamera
                    }, completion: nil)

                })
        }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

I figured it out, turns out the iOS simulator doesn't support flyover. 我发现,iOS模拟器不支持跨线。 So when I run it on a real device, my beautiful flyover animation appears just like I expect. 因此,当我在真实的设备上运行它时,我的漂亮的天桥动画就会像我期望的那样出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM