Closed gyf-lancelot closed 8 years ago
func setupSwipeGuestures() { let upSwipe = UISwipeGestureRecognizer(target:self, action: Selector("swipeUp")) upSwipe.numberOfTouchesRequired = 1 upSwipe.direction = UISwipeGestureRecognizerDirection.Up self.view.addGestureRecognizer(upSwipe)
let downSwipe = UISwipeGestureRecognizer(target:self, action: Selector("swipeDown"))
downSwipe.numberOfTouchesRequired = 1
downSwipe.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(downSwipe)
let leftSwipe = UISwipeGestureRecognizer(target:self, action: Selector("swipeLeft"))
leftSwipe.numberOfTouchesRequired = 1
leftSwipe.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(leftSwipe)
let rightSwipe = UISwipeGestureRecognizer(target:self, action: Selector("swipeRight"))
rightSwipe.numberOfTouchesRequired = 1
rightSwipe.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(rightSwipe)
}
滑动事件定义
func reflowUp()
{
copyToMtiles()
var index:Int
for var i = dimension - 1; i > 0; i--
{
for j in 0..<dimension
{
index = self.dimension * i + j
if(mtiles[index - self.dimension] == 0 && (mtiles[index] > 0))
{
mtiles[index - self.dimension] = mtiles[index]
mtiles[index] = 0
var subindex:Int = index
while(subindex + self.dimension < mtiles.count)
{
if(mtiles[subindex + self.dimension] > 0)
{
mtiles[subindex] = mtiles[subindex + self.dimension]
mtiles[subindex + self.dimension] = 0
}
subindex += self.dimension
}
}
}
}
copyFromMtiles()
}
func reflowDown()
{
copyToMtiles()
var index:Int
for i in 0..<dimension - 1
{
for j in 0..<dimension
{
index = self.dimension * i + j
if(mtiles[index + self.dimension] == 0 && (mtiles[index] > 0))
{
mtiles[index + self.dimension] = mtiles[index]
mtiles[index] = 0
var subindex:Int = index
while((subindex - self.dimension) >= 0 )
{
if(mtiles[subindex - self.dimension] > 0)
{
mtiles[subindex] = mtiles[subindex - self.dimension]
mtiles[subindex - self.dimension] = 0
}
subindex -= self.dimension
}
}
}
}
copyFromMtiles()
}
func reflowLeft()
{
copyToMtiles()
var index:Int
for i in 0..<dimension
{
for var j = dimension - 1; j > 0; j--
{
index = self.dimension * i + j
if(mtiles[index - 1] == 0 && (mtiles[index] > 0))
{
mtiles[index - 1] = mtiles[index]
mtiles[index] = 0
var subindex:Int = index
while((subindex + 1) < i * dimension + dimension)
{
if(mtiles[subindex + 1] > 0)
{
mtiles[subindex] = mtiles[subindex + 1]
mtiles[subindex + 1] = 0
}
subindex += 1
}
}
}
}
copyFromMtiles()
}
func reflowRight()
{
copyToMtiles()
var index:Int
for i in 0..<dimension
{
for j in 0..<dimension - 1
{
index = self.dimension * i + j
if(mtiles[index + 1] == 0 && (mtiles[index] > 0))
{
mtiles[index + 1] = mtiles[index]
mtiles[index] = 0
var subindex:Int = index
while((subindex - 1) < i * dimension - 1)
{
if(mtiles[subindex - 1] > 0)
{
mtiles[subindex] = mtiles[subindex - 1]
mtiles[subindex - 1] = 0
}
subindex -= 1
}
}
}
}
copyFromMtiles()
}
滑动事件响应