regiondidchange在app load swift上多次调用 [英] regiondidchange called several times on app load swift

查看:144
本文介绍了regiondidchange在app load swift上多次调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图,当我平移或输入位置并导航到它时,我想要一个简单的打印功能运行。我已经完成了这项工作,但是,当我第一次加载应用程序时,它会多次调用该打印函数,直到它完成放大。有没有办法不计算应用程序加载区域更改的初始值?

I have a map that when i pan away or type in a location and navigate to it that I want a simple print function to run. I have this accomplished, however, when i first load the app it calls that print function several times until it is finished zooming in. Is there a way to NOT count the initial on app load region change?

推荐答案

答案终于在这里找到了http://ask.ttwait.com/que/5556977

answer finally found herehttp://ask.ttwait.com/que/5556977

private var mapChangedFromUserInteraction = false

private func mapViewRegionDidChangeFromUserInteraction() -> Bool {
let view = self.mapView.subviews[0]
//  Look through gesture recognizers to determine whether this region change is from user interaction
if let gestureRecognizers = view.gestureRecognizers {
    for recognizer in gestureRecognizers {
        if( recognizer.state == UIGestureRecognizerState.Began || recognizer.state == UIGestureRecognizerState.Ended ) {
            return true
        }
    }
}
return false
}

func mapView(mapView: MKMapView, regionWillChangeAnimated animated:    
Bool) {
mapChangedFromUserInteraction =   
mapViewRegionDidChangeFromUserInteraction()
if (mapChangedFromUserInteraction) {
    // user changed map region
}
}

func mapView(mapView: MKMapView, regionDidChangeAnimated animated:   
Bool) {
if (mapChangedFromUserInteraction) {
    // user changed map region
}
}

这篇关于regiondidchange在app load swift上多次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆