Touch

Touch can be detected by the application at the beginning, during (move) ad the end using different provided functions

For example responding to a touch (or click) uses the touchesBegan function.

override func touchesBegan(_ touches: Set, with event: UIEvent?)
{
	for touch in touches
	{
		let location = touch.location(in: self)
	}
}

This code detects the beginning of a touch and returns the location from touches set. This could be used to place an item or with SpriteKit, a node.

touchesMoved and touchesEnded could be used to detect movement during a touch and when the touch ends.

override func touchesMoved(_ touches: Set, with event: UIEvent?)
{
	for touch in touches
	{
		let location = touch.location(in: self)
	}
}
or
override func touchesEnded(_ touches: Set, with event: UIEvent?)
{
	for touch in touches
	{
		let location = touch.location(in: self)
	}
}

More information can be found the Help for UITouch class


Index


Comments, Corrections, Suggestions: David Bourne (david@boomer.org)
My iOS and tvOS Apps and iBooks