Reputation: 228
I have a vertical view and vertical slider on screen next to each other. They have almost same size. I want this view to move according to position of slider. I was trying this way:
if oldValue < Int(sender.value) {
viewToMoveTopYConstreint.constant = viewToMoveTopYConstreint.constant - heightOfMovement
oldValue = Int(sender.value)
} else if oldValue > Int(sender.value) {
viewToMoveTopYConstreint.constant = viewToMoveTopYConstreint.constant + heightOfMovement
oldValue = Int(sender.value)
}
heightOfMovement is value to move my view for – e.g. 5 points
If I move slider slowly, view moves pretty accurate, but if I do it quickly, view moves in the way, like I only changed one value instead of twenty.
I know I can try to do it with "for in", but I was wondering is there a more proficient way to do this.
Upvotes: 0
Views: 584
Reputation: 10199
I think the problem is that you don't use the sliders value
property, but instead only add some heightOfMovement
(nobody except you knows where this value comes from).
I think the following would be more straight-forward:
viewToMoveTopYConstreint
to viewToMoveTopYConstraint
(just a spelling mistake :-)minValue
of the slider to 0
maxValue
of the slider to the height of the view to be moved@IBAction
just do the following: viewToMoveTopYConstraint.constant = sender.value
Upvotes: 1