How to put iOS Magnifying Glass effect on Google Maps (GMSMapKit)

感情迁移 提交于 2019-12-13 05:03:03

问题


How to put the UITextView texting editing Magnifying Glass on the Google Maps GMSMapView

For example I have a GMSMapView to show my current location I want to trigger a overlay Magnifying Glass view when calling delegate methods mapView:didChangeCameraPosition: and mapView:willMove: in GMSMapViewDelegate

The purpose is to provide an overlay zooming subView according to the user tapping coordinates (like github.com/acoomans/iOS-MagnifyingGlass did on ImageView)

Please let me know if this is possible for Google Maps for iOS or if iOS MapKit can support this kind of customization

Update #2: mapView.addSubView(mapSubView) works now. But it pollutes the Main GMSMapView

Update #1: I tried mapView.addSubView, it seems does not work for GMSMapView although inherited from UIView

The intention of below code snippet is to retrieve user's touch point at the map and converts it into CGPoint for creating a second GMSMapView

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
    println("Tapping at (\(coordinate.latitude), \(coordinate.longitude))")

    // 1. retrieve the user touch position as CLLocationCoordinate2D
    let cameraPosition = GMSCameraPosition.cameraWithLatitude(coordinate.latitude, longitude: coordinate.longitude, zoom: 20) 

    // 2. convert it into CGPoint
    let screenTouchPoints = mapView.projection.pointForCoordinate(coordinate)

    // 3. set the CGRect for init the mapSubView
    let frame = CGRectMake(screenTouchPoints.x, screenTouchPoints.y, 100, 100)
    mapSubView = GMSMapView.mapWithFrame(frame, camera: cameraPosition)

    // 4. Finally add to the main Map View
    mapView.addSubview(mapSubView)
}

回答1:


It seems plausible with a GMSMapView. Maybe have a second GMSMapView on top of the original(high corner radius to create a circle?) and animate the alpha and scale along with the zoom level within the second map. Do this whenever mapView:didChangeCameraPosition etc is called.




回答2:


By taking reference to this Github Project, GMSMapView can also be magnified by putting the view hierarchy in this way:

View Controller > Magnifying View > The View want to be zoomed

The core rendering mechanism is - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, self.frame.size.width/2, self.frame.size.height/2 ); CGContextScaleCTM(context, scale, scale); CGContextTranslateCTM(context, -touchPoint.x, -touchPoint.y + (self.scaleAtTouchPoint? 0 : self.bounds.size.height/2)); [self.viewToMagnify.layer renderInContext:context]; }

loupe = ACLoupe() magnifyingGlass = ACMagnifyingGlass() magnifyingView = ACMagnifyingView(frame: self.view.frame) magnifyingView.magnifyingGlass = loupe

magnifyingView.addSubview(Your_Subview_here)

by this method the magnifying view can capture current frame context, because Magnifying View is the container of other views so that the capturing can show the current UI situation and zoom by 1.5 times (default scale factor)



来源:https://stackoverflow.com/questions/31142272/how-to-put-ios-magnifying-glass-effect-on-google-maps-gmsmapkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!