Discussion:
touchesMoved value setting
Eric E. Dolecki
2018-09-18 12:44:00 UTC
Permalink
I have a UI control that can be adjusted up and down using touch & drag.
I've been asked to provide a control value based on how far the drag is via
distance. So far so good.

What my designer wants is a value change of every 20 pixels or so (control
is 150px tall @ the moment) - so every 20 pixels = a change of 1. This will
require multiple touch and drags but he's fine with it.

The math is probably simple, but it's eluding me this morning. How can I
easily convert my distance (I also have an increment Bool so I know whether
it's addition or subtraction) to an appropriate value?

Eric
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
Alastair Houghton
2018-09-18 13:01:38 UTC
Permalink
Post by Eric E. Dolecki
I have a UI control that can be adjusted up and down using touch & drag.
I've been asked to provide a control value based on how far the drag is via
distance. So far so good.
What my designer wants is a value change of every 20 pixels or so (control
require multiple touch and drags but he's fine with it.
The math is probably simple, but it's eluding me this morning. How can I
easily convert my distance (I also have an increment Bool so I know whether
it's addition or subtraction) to an appropriate value?
I’m not sure you’ve described the problem particularly clearly, because when I read your e-mail I came the conclusion that you just need to divide your distance by 20, but that can’t be right otherwise you’d have worked it out yourself…

Kind regards,

Alastair.

--
http://alastairs-place.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@m
Richard Charles
2018-09-18 13:03:00 UTC
Permalink
Post by Eric E. Dolecki
I have a UI control that can be adjusted up and down using touch & drag.
I've been asked to provide a control value based on how far the drag is via
distance. So far so good.
What my designer wants is a value change of every 20 pixels or so (control
I think you mean points not pixels.

Not familiar with UI controls but this sounds very similiar to NSSlider.

– maxValue
– minValue
Post by Eric E. Dolecki
This will require multiple touch and drags but he's fine with it.
This does not sound right. I think something is wrong.

--Richard Charles

_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-i
Eric E. Dolecki
2018-09-18 13:15:53 UTC
Permalink
I have a currentValue (Int).

I have a distance of the moved. For every 20 pixels, increment or decrement
the currentValue by 1.

If I do this:

let tVal = Int(distanceValue / 20)
if increment {
currentValue = currentValue + tVal
if currentValue > maxValue { currentValue = maxValue }
} else {
currentValue = currentValue - tVal
if currentValue > maxValue { currentValue = maxValue }
}

Once the distance number gets high enough, I start to get tVal values of 2,
3, 4, etc. I think my logic is messed up here.
Post by Eric E. Dolecki
Post by Eric E. Dolecki
I have a UI control that can be adjusted up and down using touch & drag.
I've been asked to provide a control value based on how far the drag is
via
Post by Eric E. Dolecki
distance. So far so good.
What my designer wants is a value change of every 20 pixels or so
(control
I think you mean points not pixels.
Not familiar with UI controls but this sounds very similiar to NSSlider.
– maxValue
– minValue
Post by Eric E. Dolecki
This will require multiple touch and drags but he's fine with it.
This does not sound right. I think something is wrong.
--Richard Charles
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent
Quincey Morris
2018-09-18 14:33:30 UTC
Permalink
Post by Eric E. Dolecki
Once the distance number gets high enough, I start to get tVal values of 2,
3, 4, etc. I think my logic is messed up here.
currentValue = currentValue ± tVal
currentValue = originalValue ± tVal // original value at time of touchesBegan
and ‘distanceValue’ has to be the *accumulated* distance since the touchesBegan. Trying to do this using the distance moved since the last touchesMoved is wrong.

BTW, I think it’s easier to use a UIPanGestureRecognizer.

_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

T
Eric Dolecki
2018-09-18 18:51:49 UTC
Permalink
Ahhh thanks!!

The distance is being accumulated appropriately.

Sent from my iPhone X.

________________________________
From: Quincey Morris <***@rivergatesoftware.com>
Sent: Tuesday, September 18, 2018 10:33 AM
To: Eric E. Dolecki
Cc: Cocoa Dev
Subject: Re: touchesMoved value setting

On Sep 18, 2018, at 06:15 , Eric E. Dolecki <***@gmail.com<mailto:***@gmail.com>> wrote:

Once the distance number gets high enough, I start to get tVal values of 2,
3, 4, etc. I think my logic is messed up here.

Yes, it’s messed up. Instead of this:

currentValue = currentValue ± tVal

you need this:

currentValue = originalValue ± tVal // original value at time of touchesBegan

and ‘distanceValue’ has to be the *accumulated* distance since the touchesBegan. Trying to do this using the distance moved since the last touchesMoved is wrong.

BTW, I think it’s easier to use a UIPanGestureRecognizer.

_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-i

Loading...