Rodrigo Ruiz
Rodrigo Ruiz

Reputation: 4355

MKMapView not staying rotated

Easy to reproduce: - create a new project - put an MKMapView on the screen - try to rotate it with 2 fingers

It rotates a little and stops, and when you release the fingers, it goes back to the original position.

How do I make it stay rotated? And rotate as much as I want?

I'm using latest iOS (8.something), iPhone 6 simulator and Swift.

Upvotes: 0

Views: 1018

Answers (4)

Rodrigo Ruiz
Rodrigo Ruiz

Reputation: 4355

I figured out the problem. Actually there is no solution, what was happening is that MKMapView does not allow you to stay rotated if the map region is too big. If you zoom in you can rotate normally.

Upvotes: 7

user4615157
user4615157

Reputation:

Please try this Gloabally declare :

let regionRadius: CLLocationDistance = 1000

And in viewdidload:

let initialLocation = CLLocation(latitude: 21.282778, longitude: -157.829444)
    centerMapOnLocation(initialLocation)

And then create a helper class:

func centerMapOnLocation(location: CLLocation) {
        let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
            regionRadius * 2.0, regionRadius * 2.0)
        mapview.setRegion(coordinateRegion, animated: true)
    }

Upvotes: 1

Manuel Escrig
Manuel Escrig

Reputation: 2835

You have to override CLLocationManager.didUpdateLocations (part of CLLocationManagerDelegate) to get notified when the location manager retrieves the current location and don't do anything there:

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    // Don't do update the map to the new location
}

Upvotes: 0

Vinod N
Vinod N

Reputation: 148

Try with rotateEnabled property of MKMapView :

rotateEnabled - A Boolean value indicating whether the map camera’s heading information is used.

Declaration

SWIFT var rotateEnabled: Bool

When this property is set to YES and a valid camera is associated with the map, the camera’s heading angle is used to rotate the plane of the map around its center point. When this property is set to NO, the camera’s heading angle is ignored and the map is always oriented so that true north is situated at the top of the map view.

Upvotes: 0

Related Questions