我有带UIScrollView的ViewController,一些UIImages和UIButtons。在情节提要中,我将UIScrollView的大小设置为:宽度:320,高度:570
我想在加载ViewController时更改UIScrollView的Contentsize。
我在viewDidLoad中添加了一侧:
scrlMain.contentSize = CGSize(width: 320,height: 790)
Run Code Online (Sandbox Code Playgroud)
另外,我在viewDidLayoutSubviews中添加了代码:
self.scrlMain.translatesAutoresizingMaskIntoConstraints = true
Run Code Online (Sandbox Code Playgroud)
但是我的UIScrollView仍然是最后一个大小=570。我不能使用viewDidAppear,因为当我按下按钮时,它需要它来改变颜色。更改颜色后,我的UIScrollView向上移动。
我做错什么了?
所有代码:
override func viewDidLoad() {
super.viewDidLoad()
scrlMain.delegate = self
scrlMain.contentSize = CGSizeMake(320, 790)
}
override func viewDidLayoutSubviews() {
self.scrlMain.translatesAutoresizingMaskIntoConstraints = true
self.scrlMain.contentSize = CGSize(width: self.scrlMain.frame.width, height: 60.0 + 5 * (self.scrlMain.frame.width / 16.0 * 5.0));
}
Run Code Online (Sandbox Code Playgroud) 我想检测一下用户何时完成了“范围”滑块的移动。我尝试使用function SliderAction(sender: RangeSlider),但是在滑块中得到了每个移动点。我想我需要使用以下功能:func endTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?),但这是行不通的。我该怎么做?
我regionDidChangeAnimated用于我的mapView.我想检测用户缩放或拖动地图的时间.正在检测拖动,但我似乎无法检测用户缩放地图的时间.我试着用:
func mapView(mapView: MKMapView, regionWillChangeAnimated animated: Bool) {
print("region will change")
}
Run Code Online (Sandbox Code Playgroud)
但是当我缩放我的地图时,它不起作用.
完整代码:
var locationManager: CLLocationManager = CLLocationManager()
var startLocation: CLLocation!
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
//get current location
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
startLocation = nil
let mapDragRecognizer = UIPanGestureRecognizer(target: self, action: "didDragMap:")
mapDragRecognizer.delegate = self
self.mapView.addGestureRecognizer(mapDragRecognizer)
self.mapView.pitchEnabled = true
self.mapView.showsBuildings = true
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [CLLocation]) {
let location = locations.last …Run Code Online (Sandbox Code Playgroud) swift ×3
ios ×2
apple-maps ×1
contentsize ×1
mapkit ×1
mkmapview ×1
rangeslider ×1
slider ×1
uicontrol ×1
uiscrollview ×1