How to move single SKspritenode from array - ios

I have an array of sprites and I move it when click on it, the problem is that it is moving all the sprites and I want it to move a single element, how can I do this? thank you in advance
This is my code:
var containerPieces: [ContainerPieces] = []
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
let rsCurrent = self.atPoint(location)
for nodo in containerPieces {
let rsBody = nodo.block.physicsBody
if rsBody == rsCurrent.physicsBody {
if nodo.block.frame.contains(location) {
nodo.block.position = location
nodo.block.run(blinkAnimation(), withKey:"wiggle")
isFingerOnPaddle = true
}
}
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if isFingerOnPaddle {
let touch = touches.first
let touchLocation = touch!.location(in: self)
let previousLocation = touch!.previousLocation(in: self)
for nodo in containerPieces{
var paddleX = nodo.block.position.x + (touchLocation.x - previousLocation.x)
var paddleY = nodo.block.position.y + (touchLocation.y - previousLocation.y)
paddleX = max(paddleX, nodo.block.size.width/2)
paddleX = min(paddleX, size.width - nodo.block.size.width/2)
paddleY = max(paddleY, nodo.block.size.width/2)
paddleY = min(paddleY, size.width - nodo.block.size.width/2)
nodo.block.position = CGPoint(x: paddleX, y: paddleY)
}
}
}

Related

UIButton Frame changed After Move from one Position To Another

I have 1 UIButton in StoryBoard like below screen and I move UIButton from one position to another position by following this Answer.
Edit
Another thing that I want to rotate UIButton and for that I have tried below code and it works fine but after rotating UIButton when I try to move UIButton position from 1 place to another then UIButton frame is changed.
Entire UIButton code.
class DraggableButton: UIButton {
var localTouchPosition : CGPoint?
var lastRotation: CGFloat = 0
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// ROTATION CODE
let rotate = UIRotationGestureRecognizer(target: self, action:#selector(rotatedView(_:)))
self.addGestureRecognizer(rotate)
}
// SCROLLING CONTENT FROM ONE POSITION TO ANOTHER
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let touch = touches.first
self.localTouchPosition = touch?.preciseLocation(in: self)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
let touch = touches.first
guard let location = touch?.location(in: self.superview), let localTouchPosition = self.localTouchPosition else{
return
}
self.frame.origin = CGPoint(x: location.x - localTouchPosition.x, y: location.y - localTouchPosition.y)
print(self.frame)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
self.localTouchPosition = nil
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
self.localTouchPosition = nil
}
// ROTATION CODE
#objc func rotatedView(_ sender: UIRotationGestureRecognizer) {
var originalRotation = CGFloat()
if sender.state == .began {
sender.rotation = lastRotation
originalRotation = sender.rotation
} else if sender.state == .changed {
let newRotation = sender.rotation + originalRotation
sender.view?.transform = CGAffineTransform(rotationAngle: newRotation)
} else if sender.state == .ended {
lastRotation = sender.rotation
}
}
}
Edit 1
I uploaded issue video.
Edit 2
If I used UIButton Rotation and Movement Code separately then it works but when I write both code it generate this issue.
I believe the issue is that the rotation is about the center of the view, so when you apply the rotation the frame size increases which throws off the distance relative to the origin of the frame.
I was able to fix this by moving the view relative to its center:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let touch = touches.first
guard let location = touch?.location(in: self.superview) else { return }
// Store localTouchPosition relative to center
self.localTouchPosition = CGPoint(x: location.x - self.center.x, y: location.y - self.center.y)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
let touch = touches.first
guard let location = touch?.location(in: self.superview), let localTouchPosition = self.localTouchPosition else{
return
}
self.center = CGPoint(x: location.x - localTouchPosition.x, y: location.y - localTouchPosition.y)
print(self.frame)
}

use two sprite objects at the same time with single touch?

Currently, I can only use one at a time, and not make the two paddles (one on each side of the screen) act independently when different finger movements are used with each one. Here is the class. Any ideas?
let BallCategoryName = "ball"
let GameMessageName = "gameMessage"
let BallCategory : UInt32 = 0x1 << 0
let LeftCategory : UInt32 = 0x1 << 1
let BlockCategory : UInt32 = 0x1 << 2
let PaddleCategory : UInt32 = 0x1 << 3
let BorderCategory : UInt32 = 0x1 << 4
class GameScene: SKScene, SKPhysicsContactDelegate {
var isFingerOnPaddleL = false
var isFingerOnPaddleR = false
override func didMove(to view: SKView) {
super.didMove(to: view)
let borderBody = SKPhysicsBody(edgeLoopFrom: self.frame)
borderBody.friction = 0
self.physicsBody = borderBody
physicsWorld.gravity = CGVector(dx: 0.0, dy: 0.0)
physicsWorld.contactDelegate = self
let ball = childNode(withName: BallCategoryName) as! SKSpriteNode
ball.physicsBody!.applyImpulse(CGVector(dx: 2.0, dy: -2.0))
let paddleL = childNode(withName: "paddleL") as! SKSpriteNode
//let paddleR = childNode(withName: "paddleR") as! SKSpriteNode
let leftRect = CGRect(x: frame.origin.x, y: frame.origin.y, width: 1, height: frame.size.height)
let left = SKNode()
left.physicsBody = SKPhysicsBody(edgeLoopFrom: leftRect)
addChild(left)
left.physicsBody!.categoryBitMask = LeftCategory
ball.physicsBody!.categoryBitMask = BallCategory
paddleL.physicsBody!.categoryBitMask = PaddleCategory
borderBody.categoryBitMask = BorderCategory
ball.physicsBody!.contactTestBitMask = LeftCategory
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
let touchLocation = touch!.location(in: self)
if let body = physicsWorld.body(at: touchLocation) {
if body.node!.name == "paddleL" {
print("Began touch on paddleL")
isFingerOnPaddleL = true
}
else if body.node!.name == "paddleR" {
print("Began touch on paddleR")
isFingerOnPaddleR = true
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
// 1
if isFingerOnPaddleL {
// 2
let touch = touches.first
let touchLocation = touch!.location(in: self)
let previousLocation = touch!.previousLocation(in: self)
// 3
let paddle = childNode(withName: "paddleL") as! SKSpriteNode
// 4
var paddleY = paddle.position.y + (touchLocation.y - previousLocation.y)
// 5
paddleY = max(paddle.size.height/2, paddleY)
paddleY = min(size.height - paddle.size.height/2, paddleY)
// 6
paddle.position = CGPoint(x: paddle.position.x, y: paddleY)
}
else if isFingerOnPaddleR {
// 2
let touch = touches.first
let touchLocation = touch!.location(in: self)
let previousLocation = touch!.previousLocation(in: self)
// 3
let paddle = childNode(withName: "paddleR") as! SKSpriteNode
// 4
var paddleY = paddle.position.y + (touchLocation.y - previousLocation.y)
// 5
paddleY = max(paddle.size.height/2, paddleY)
paddleY = min(size.height - paddle.size.height/2, paddleY)
// 6
paddle.position = CGPoint(x: paddle.position.x, y: paddleY)
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if (isFingerOnPaddleL == true) {
isFingerOnPaddleL = false
}
else if (isFingerOnPaddleR == true) {
isFingerOnPaddleR = false
}
}
func didBegin(_ contact: SKPhysicsContact) {
// 1
var firstBody: SKPhysicsBody
var secondBody: SKPhysicsBody
// 2
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
} else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
// 3
if firstBody.categoryBitMask == BallCategory && secondBody.categoryBitMask == LeftCategory {
print("Hit left. First contact has been made.")
}
}
}
You can process the paddles independently by tracking each touch throughout its lifecycle (began/moved/ended). First, define a dictionary with the touch object as the key and the node's name as the value
var touchTracker:[UITouch:String] = [:]
then in touchesBegan, store the name of paddle(s) touched by the user
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchLocation = touch.location(in: self)
let node = atPoint(touchLocation)
if let name = node.name {
if name == "paddleL" {
print("Began touch on paddleL")
touchTracker[touch] = name
}
else if name == "paddleR" {
print("Began touch on paddleR")
touchTracker[touch] = name
}
}
}
}
In touchesMoved, use the touch object to retrieve the node's name from the dictionary, and use the name to access the appropriate paddle.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchLocation = touch.location(in: self)
if let name = touchTracker[touch] {
if let paddle = childNode(withName: name) as? SKSpriteNode {
// Move a paddle
paddle.position = CGPoint(x:paddle.position.x, y:touchLocation.y)
}
}
}
}
Lastly, remove the touch/name from the dictionary when a touch ends.
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
if touchTracker[touch] != nil {
touchTracker.removeValue(forKey: touch)
}
}
}

Trying to move / drag SKSpriteNode in y axis

I'm trying to create a small game ,and in there there is a pipe , and i want to move that pipe along with the y axis , i want to do thins for finger swipe , i tried to do this with touches began but its doesn't looks smooth , so i tried to use uipangesture , but in not familiar with the sprite integration ,
can someone help me to achive this
class GameScene: SKScene,SKPhysicsContactDelegate {
var pipeTextureUp:SKTexture!
var pipeTextureDown:SKTexture!
var pipeUp:SKSpriteNode!
var pipeDown:SKSpriteNode!
var circleTouch: UITouch?
var verticalPipeGap:Double = 60.0
var moveStatus: Bool!
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.whiteColor()
//set the gravity
self.physicsWorld.gravity = CGVector(dx: 0.0, dy: 0.0)
self.physicsWorld.contactDelegate = self
//first create the pipe in a random location
pipeTextureUp = SKTexture(imageNamed: "PipeUp")
pipeTextureUp.filteringMode = .Nearest
pipeTextureDown = SKTexture(imageNamed: "PipeDown")
pipeTextureDown.filteringMode = .Nearest
pipeUp = SKSpriteNode(texture: pipeTextureUp)
pipeUp.setScale(2.0)
pipeUp.name = "pipeUp"
pipeUp.position = CGPoint(x: size.width * 0.9, y: 0.0)
pipeDown = SKSpriteNode(texture: pipeTextureDown)
pipeDown.setScale(2.0)
pipeDown.name = "pipeDown"
pipeDown.position = CGPoint(x: Double(size.width) * 0.9 , y: Double(pipeDown.size.height) + verticalPipeGap)
//addChild(pipeDown)
addChild(pipeUp)
}
func didBeginContact(contact: SKPhysicsContact) {
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch:UITouch = touches.first!
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
if let name = touchedNode.name
{
if (name == "pipeUp" || name == "pipeDown" )
{
print("touches started")
moveStatus = true
circleTouch = touch
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch:UITouch = touches.first!
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
print(positionInScene)
if let name = touchedNode.name
{
if (name == "pipeUp" || name == "pipeDown" )
{
//let fingerPoint = CGPoint(x: size.width * 0.9, y: 0.3)
let actionUpMove:SKAction = SKAction.moveToY(positionInScene.y, duration: 1.0)
pipeUp.runAction(actionUpMove)
pipeUp.position.y = positionInScene.y
}
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch:UITouch = touches.first!
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
if let name = touchedNode.name
{
if (name == "pipeUp" || name == "pipeDown" )
{
//let fingerPoint = CGPoint(x: size.width * 0.9, y: 0.3)
circleTouch = nil
}
}
}
}
If you want to intercept your swiping along Y coordinate you could put this code in didMoveToView:
let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameScene.swipedUp(_:)))
swipeUp.direction = .Up
swipeUp.cancelsTouchesInView = true
swipeUp.delaysTouchesBegan = true
view.addGestureRecognizer(swipeUp)
let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameScene.swipedDown(_:)))
swipeDown.direction = .Down
swipeDown.cancelsTouchesInView = true
swipeDown.delaysTouchesBegan = true
view.addGestureRecognizer(swipeDown)
Then your methods are:
func swipedUp(sender:UISwipeGestureRecognizer){
print("swiped up")
}
func swipedDown(sender:UISwipeGestureRecognizer){
print("swiped down")
}
UPDATE : apparently this is what i had to do ,
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch:UITouch = touches.first!
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
if let name = touchedNode.name
{
if (name == "pipeUp" || name == "pipeDown" )
{
handleTouch(touches.first!, name: name)
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch:UITouch = touches.first!
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
if let name = touchedNode.name
{
if (name == "pipeUp" || name == "pipeDown" )
{
handleTouch(touches.first!, name: name)
}
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch:UITouch = touches.first!
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
if let name = touchedNode.name
{
if (name == "pipeUp" || name == "pipeDown" )
{
handleTouch(touches.first!, name: name)
}
}
}
func handleTouch(touch: UITouch , name : String) {
let location = touch.locationInNode(self) // get the current point
let node = self.nodeAtPoint(location) //get the current node based on the touched location
let previousLocation = touch.previousLocationInNode(self) //get the previous location in node
let diff = location.y - previousLocation.y; //get the different of location
let newPosition = CGPointMake(node.position.x, node.position.y + diff);
var newPipeDownPosition :CGPoint;
if (name == "pipeDown" )
{
newPipeDownPosition = CGPointMake(self.pipeUp.position.x, self.pipeUp.position.y + diff);
pipeDown.position.y = newPosition.y
pipeUp.position.y = newPipeDownPosition.y
}else{
newPipeDownPosition = CGPointMake(self.pipeDown.position.x, self.pipeDown.position.y + diff);
pipeUp.position.y = newPosition.y
pipeDown.position.y = newPipeDownPosition.y
}
}
now the pipe moves according to top and down direction

Character is not moving in desired scene in scenekit

i want to move my character in scene kit .i have a map as at github Fpscontroller and i want my character move in this map but when ever i touch to move character it jumps and don,t know where is goes here is my code.`
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
if CGRectContainsPoint(gameView.virtualDPadBounds(), touch.locationInView(gameView)) {
if padTouch == nil {
padTouch = touch
controllerStoredDirection = float2(0.0)
}
} else if panningTouch == nil {
panningTouch = touches.first
}
if padTouch != nil && panningTouch != nil {
break
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = panningTouch {
let displacement = (float2(touch.locationInView(view)) - float2(touch.previousLocationInView(view)))
panCamera(displacement)
}
if let touch = padTouch {
let displacement = (float2(touch.locationInView(view)) - float2(touch.previousLocationInView(view)))
controllerStoredDirection = clamp(mix(controllerStoredDirection, displacement, t: ViewController.controllerAcceleration), min: -ViewController.controllerDirectionLimit, max: ViewController.controllerDirectionLimit)
}
}
func commonTouchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = panningTouch {
if touches.contains(touch) {
panningTouch = nil
}
}
if let touch = padTouch {
if touches.contains(touch) || event?.touchesForView(view)?.contains(touch) == false {
padTouch = nil
controllerStoredDirection = float2(0.0)
}
}
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
commonTouchesEnded(touches!, withEvent: event)
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
commonTouchesEnded(touches, withEvent: event)
}
i followed apple fox example for moving with touch and in my viewcontroller
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func walkGestureRecognized(gesture: UIPanGestureRecognizer) {
if gesture.state == UIGestureRecognizerState.Ended || gesture.state == UIGestureRecognizerState.Cancelled {
gesture.setTranslation(CGPointZero, inView: self.view)
}
}
func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {
//get walk gesture translation
let translation = walkGesture.translationInView(self.view)
//create impulse vector for hero
let angle = heroNode.presentationNode.rotation.w * heroNode.presentationNode.rotation.y
var impulse = SCNVector3(x: max(-1, min(1, Float(translation.x) / 50)), y: 0, z: max(-1, min(1, Float(-translation.y) / 50)))
impulse = SCNVector3(
x: impulse.x * cos(angle) - impulse.z * sin(angle),
y: 0,
z: impulse.x * -sin(angle) - impulse.z * cos(angle)
)
heroNode.physicsBody?.applyForce(impulse, impulse: true)
let scene = gameView.scene!
let direction = characterDirection()
let groundNode = character.walkInDirection(direction, time: time, scene: scene, groundTypeFromMaterial:groundTypeFromMaterial)
setting character position and direction....
private func characterDirection() -> float3 {
let controllerDirection = self.controllerDirection()
var direction = float3(controllerDirection.x, 0.0, controllerDirection.y)
if let pov = gameView.pointOfView {
let p1 = pov.presentationNode.convertPosition(SCNVector3(direction), toNode: nil)
let p0 = pov.presentationNode.convertPosition(SCNVector3Zero, toNode: nil)
direction = float3(Float(p1.x - p0.x), 0.0, Float(p1.z - p0.z))
if direction.x != 0.0 || direction.z != 0.0 {
direction = normalize(direction)
}
}
return direction
}
there are actually two scenes called in view controller class one is empty scene called for mapNode as hereoNode and other is character sceneNode
let scene = SCNScene()
scene.rootNode.addChildNode(heroNode)
let personScene = SCNScene(named: "game.scnassets/person.scn")!
personNode = personScene.rootNode.childNodeWithName("person", recursively: true)
personNode?.position = SCNVector3(x:4.5,y:0,z:25)
node.addChildNode(personNode)
scene.rootNode.addChildNode(character.node)
i am updating my question with some more details as you can see in this screen shot image i m attatching here enter image description here i want to move this fox in map with touch but it is not working it just jump and go out from map when i touch .....plz someone tell me where is my fault in code

Detecting when a user taps a SKSpriteNode

I'm new to swift programming and I decided I would make a simple game to start with SpriteKit. I have a SpriteNode that is supposed to pick 1 of 6 locations and move there when it is tapped, however from the methods I've seen I can't figure out how to implement it (again I'm new at this) Here is my code from the GameScene.swift file:
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
let screenSize: CGRect = UIScreen.mainScreen().bounds
let greenTileWidth = screenSize.width * 0.5
let greenTileHeight = screenSize.height * 0.33
let greenTilePositionY = [greenTileHeight / 2, greenTileHeight / 2 + greenTileHeight, greenTileHeight / 2 + greenTileHeight * 2 ]
let greenTilePositionX = [greenTileWidth / 2, greenTileWidth / 2 + greenTileWidth]
let backgroundTile = SKSpriteNode(imageNamed: "whiteTile")
backgroundTile.size.width = screenSize.width * 100
backgroundTile.size.height = screenSize.height * 100
addChild(backgroundTile)
let greenTile = SKSpriteNode(imageNamed: "greenTile")
greenTile.size.width = greenTileWidth
greenTile.size.height = greenTileHeight
greenTile.position.y = greenTilePositionY[0]
greenTile.position.x = greenTilePositionX[0]
greenTile.userInteractionEnabled = true
addChild(greenTile)
var randomX:Int = 0
var randomY:Int = 0
func getRandomY() -> Int{
randomY = Int(arc4random_uniform(26))%3
return randomY
}
func getRandomX() -> Int{
randomX = Int(arc4random_uniform(26))%2
return randomX
}
func moveGreenTile(){
greenTile.position.x = greenTilePositionX[randomX]
greenTile.position.y = greenTilePositionY[randomY]
}
getRandomX()
getRandomY()
moveGreenTile()
}
when the SpriteNode greenTile is tapped, getRandomY() getRandomX() and moveGreenTile() should be called.
First you have to set the name attribute of your SKSpriteNodes:
greenTile.name = "greenTile"
First I see some errors in your code. The return values of getRandomX and getRandomY never get really used. Because you set the randomX and randomY variables without actually calling getRandom. So you should update it to:
func moveGreenTile(){
greenTile.position.x = greenTilePositionX[getRandomX()]
greenTile.position.y = greenTilePositionY[getRandomY()]
}
That way you only have to call moveGreenTile and it will call the getRandom methods by itself.
Then you have to use the touchesBegan method to check if the user touches the screen. So with the name you can check if the user touched the greenTile by checking the name you've set earlier:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch in touches{
let location = touch.locationInNode(self)
let node:SKNode = self.nodeAtPoint(location)
if(node.name == "greenTile"){
moveGreenTile()
}
}
}
This code detects tap events, not only touches, on a SKSpriteNode.
You can change how sensitive the tap gesture is by modifying TapMaxDelta.
class TapNode : SKSpriteNode {
// Tap Vars
var firstPoint : CGPoint?
var TapMaxDelta = CGFloat(10)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
init() {
let texture = SKTexture(imageNamed: "Test.png")
super.init(texture: texture, color: UIColor.clear, size: texture.size())
isUserInteractionEnabled = true
}
// ================================================================================================
// Touch Functions
// ================================================================================================
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let firstTouch = touches.first {
firstPoint = firstTouch.location(in: self)
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let firstTouch = touches.first, let firstPoint = firstPoint {
let curPoint = firstTouch.location(in: self)
if abs(curPoint.x - firstPoint.x) <= TapMaxDelta && abs(curPoint.y - firstPoint.y) <= TapMaxDelta {
print("tap yo")
}
}
}
}

Resources