設定TableView寬度為100%
選擇TableView物件

取消勾選Constrain to margins,並設定左邊和右邊的邊界為0
1)打開設定介面(在Xcode畫面右下角的位置)
2)取消勾選Constrain to margins
3)點選左邊界和右邊界
4)邊界填寫為0,有時候填寫完設定會跑掉,先點選一下其他地方,再重新填寫就可以了
5)完成設定

TableView設定的寬度完成

如果勾選了Constrain to margins
會自動留下20px的邊界

@IBAction func btnStartGPS(sender: UIButton) { let btnStartGPSLabel: String = btnStartGPS.titleLabel!.text! if((btnStartGPSLabel).rangeOfString("START")?.startIndex == (btnStartGPSLabel).startIndex){ //簡易的判斷現在是要停止或是開始 btnStartGPS.setTitle("STOP停止記錄座標", forState: UIControlState.Normal) //初始化變數 locationManager = CLLocationManager() locationManager.delegate = self //設定精確度 locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation //相當重要的一行 //如果不加的話,會在背景執行20分鐘左右,就停止記錄了 locationManager.pausesLocationUpdatesAutomatically = false if #available(iOS 9.0, *){ locationManager.allowsBackgroundLocationUpdates = true } //---請求權限--- //在APP使用期間才能使用GPS //locationManager.requestWhenInUseAuthorization() //隨時都可以使用GPS locationManager.requestAlwaysAuthorization() //---------- //設置距離篩選器,表示設備至少移動?米,才通知委託更新 locationManager.distanceFilter = 10 locationManager.startUpdatingLocation() }else{ btnStartGPS.setTitle("START開始記錄座標", forState: UIControlState.Normal) locationManager = nil } }
//座標有更新時會呼叫這裡 func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { //經緯度 var userLocationLat: String = String(locations[0].coordinate.latitude) var userLocationLon: String = String(locations[0].coordinate.longitude) var GPSText = getNowTime() + "=>" + userLocationLat + "," + userLocationLon textGPS.text = GPSText + "\n" + textGPS.text setPlistContent(GPSText) }需要設定BackgroundTask,才可以在背景執行
override func viewWillAppear(animated: Bool) { myTimer.invalidate() //停止背景執行 backgroundTask = UIBackgroundTaskInvalid } override func viewWillDisappear(animated: Bool) { //當程式進入背景時,執行這段 //這段是測試用,可以不用有這段 //監控APP是否還有在執行 myTimer.invalidate() myTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "timerMethod:", userInfo: nil, repeats: true) //加這個,才會在背景執行 //時間到了會執行這裡 backgroundTask = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler { [unowned self] in } assert(backgroundTask != UIBackgroundTaskInvalid) }
if (m_SimulateModem) {
// Delay sends by 300ms per KB uploaded.
oSession["request-trickle- delay"] = "30000";
// Delay receives by 150ms per KB downloaded.
oSession["response-trickle- delay"] = "15000";
}
測速結果